In my web.config
file I have specified some custom errors:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error">
<error statusCode="500" redirect="~/Error" />
<error statusCode="404" redirect="~/NotFound" />
</customErrors>
Now, some links, such as http://mysite.com/dsflhsdff
will be properly redirected to mysite.com/notfound
. But some links, like https://mysite.com/videoconference/0/0/0
are handled by server itself - instead of my custom error page, I am getting IIS error page (file or dir not found). In example this link - https://scyk.pl/forums/0/0/0
will produce proper 404 error (my custom error page).
What is happening here? Do I need to set up IIS custom errors manually? If so, how can I do that?
This is because ASP.NET never even knows that there has been a request for the .htm page. IIS will handle .htm pages by itself without involving ASP.NET at all.
You can get your custom page to show in one of two ways:
Get ASP.NET to process .htm pages: In IIS rightclick your website/virtual directory --> properties --> home directory/virtual directory tab --> "configuration" button under the "application settings" section --> Add the mapping. Set the custom error page for IIS: In IIS rightclick your website/virtual directory --> properties --> custom errors tab --> set the 404 error to the page your error page.
You can also handle this error in your Global.asax file in Application_Error method
e.g.
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception exc = Server.GetLastError();
// Handle HTTP errors
if (exc.GetType() == typeof(HttpException))
{
// The Complete Error Handling Example generates
// some errors using URLs with "NoCatch" in them;
// ignore these here to simulate what would happen
// if a global.asax handler were not implemented.
/*if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
return;*/
//Redirect HTTP errors to HttpError page
/*Server.Transfer("HttpErrorPage.aspx");*/
}
}
More info : http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/aspnet-error-handling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With