'ASP.NET web forms error handling for IIS errors
Lately, I have come across certain errors that custom errors can't deal with. For instance, if my code throws a runtime error such as 'object reference not set to an instance of an object', I get redirected to my custom error page.
However, when I manually type a url for a page that doesn't exist in my files, a default error page gets displayed. Let me elaborate:
Here's the troublesome url: https://localhost:44315/asd
As there is no page named 'asd' in the content, I get redirected to page that looks like this:
Below is what I have done so far for this issue:
1. Custom errors on in web.config:
<customErrors mode="On" defaultRedirect="~/myerrorpage.aspx">
</customErrors>
This works just fine for runtime errors. Or in other words, I never see the notorious yellow error page.
2. Global.asax file:
protected void Application_Error(object sender, EventArgs e)
{
Response.Redirect("/myerrorpage.aspx");
}
But as you may imagine nothing different happened. How can I solve this?
If this question has a duplicate, I would be grateful if you link it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

