Reputation: 61773
<customErrors mode="On" defaultRedirect="~/Error.aspx">
<error statusCode="500" redirect="~/500/"/>
<error statusCode="404" redirect="~/404/"/>
</customErrors>
This works fine for requests like:
~/egerg.aspx
~/wf92734eg.aspx
But for any other extension, this gives a server 404 page! How can I make the server 404 page redirect to my error page?
Upvotes: 1
Views: 2126
Reputation: 1255
This solution works on my website which is 99% webforms and 1% Razor/MVC 4 on .NET Framework 4.
In /Web.config:
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx">
<error statusCode="500" redirect="~/500/"/>
<error statusCode="404" redirect="~/404/"/>
</customErrors>
</system.web>
In the Page_Load event of your 404 handler (/404/default.aspx.cs, I assume):
protected void Page_Load(object sender, EventArgs e)
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
}
Repeat the last step for the 500 handler.
The Application_Error method is empty in /Global.asax.cs.
This solution is very similar to this one.
Upvotes: 1