[Solved] Custom error page redirect not working after deployed in IIS

on Mar 01, 2019 12:22 AM


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)

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
on Mar 01, 2019 02:29 AM

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.

    <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="" />