Sumeet
on Mar 01, 2019 12:22 AM
5729 Views
Sir,
In my web.config I have used customError tag to handle 404 with mode="ON".
Also added a global.asax and in Application_Error() method added below code:
var serverError = Server.GetLastError() as HttpException;
if (serverError != null)
{
if (serverError.GetHttpCode() == 404)
{
Server.ClearError();
Server.Transfer("/Errors/404.aspx");
}
}
But when I am publishing application to IIS and accessing, it does not handling 404.
What is the best way to handle it?
Download FREE API for Word, Excel and PDF in ASP.Net:
Download
Sumeet
on Mar 01, 2019 02:29 AM
3
This is the way i have achieved this:
In web.config file within <configuration></configuration> place below code and provide your own path of error page.
<system.webServer>
<httpErrors errorMode="Custom" existingResponse ="Replace">
<remove statusCode="404" />
<error statusCode="404" path="404.aspx" responseMode="Redirect" prefixLanguageFilePath="" />
<remove statusCode="500" />
<error statusCode="500" path="500.aspx" responseMode="Redirect" prefixLanguageFilePath="" />
<remove statusCode="403" />
<error statusCode="403" path="403.aspx" responseMode="Redirect" prefixLanguageFilePath="" />
</httpErrors>
</system.webServer>