I use Asp.Net 4 and C#.
I would like to know how to change the default beahviour of Asp.Net customErrors.
In my Web.Config file I use this settings.
<customErrors mode="On" defaultRedirect="/ErrorPages/Oops.aspx">
<error statusCode="404" redirect="/ErrorPages/404.aspx" />
</customErrors>
As you can expect if a page is not found a redirect occur to the custom page specified in Web.Config.
Requested page:
http://localhost:1372/nopagehere
Result page:
http://localhost:1372/ErrorPages/404.aspx?aspxerrorpath=/nopagehere
When I analyse the Http Header for the Result page I can see:
- a 404 Status when the page is not found
- a 302 Status for the new created url
I would like change this behavior in this way:
- when a request to a not found page has been made http://localhost:1372/nopagehere
- the result should be only http://localhost:1372/nopagehere (no 302 redirect) and with status code only on 404.
Any idea how to do it? Thanks for your time on this.
I guess you are looking for the
redirectModeattribute on your<customErrors>section.See: http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx
I think you want to set it to
redirectMode="ResponseRewrite". This throws a 404 and shows the content of your 404 page, but without redirecting to the actual 404 page.