According to @Amila's post and confirmation and completion of that post, I have same problem, I dig a lot google but had no chance to find the correct answer. The problem is when you are working with ASP.Net Web Application, whether it's an MVC or not you can't achieve custom error using the old way with Webform project.
Here the Option if you are using ASP.Net Web Application (whether it's an MVC or not):
In my scenarios I just want to define a custom error for a specific 404 error, The other error defined same as 404 error:
Senario1: Your custom page is a simple HTML file and placed in the root:
<configuration> <system.web> <customErrors mode="Off" /> </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="ErrorPage.html" responseMode="File" /> </httpErrors> </system.webServer> </configuration>
Senario2: Your custom page is an
aspx page and placed in the
root:
<configuration> <system.web> <customErrors mode="Off" /> </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="ErrorPage" responseMode="Redirect" /> </httpErrors> </system.webServer> </configuration>
Note: I remove the aspx extension due to RouteConfig.cs in ASP.net application, you can use ErrorPage.aspx if you like, it's optional.
Senario3: Your custom page is an
aspx page and placed in the
[ex: Page folder in The root (~/Page/ErrorPage.aspx)]:
The tip here that I noticed is
YOU SHOULD NOT USE~/ to the root addressing; So I just addresing without
~/ mark:
<configuration> <system.web> <customErrors mode="Off" /> </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="Page/ErrorPage" responseMode="Redirect" /> </httpErrors> </system.webServer> </configuration>