404 custom error page does not work in IIS 8.5

I recently switched to a host and had to configure client errors again in IIS.

I can go to the IIS Admin and Error pages:

Custom Errors on IIS

Then I can go to user errors and configure the settings as follows:

Customer Errors setup

This creates the my.config file as follows:

<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="ExecuteURL"> <remove statusCode="500" subStatusCode="100" /> <remove statusCode="500" subStatusCode="-1" /> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="/error_404.asp" responseMode="ExecuteURL" /> <error statusCode="500" prefixLanguageFilePath="" path="/error_500.asp" responseMode="ExecuteURL" /> <error statusCode="500" subStatusCode="100" path="/error_500.asp" responseMode="ExecuteURL" /> </httpErrors> </system.webServer> </configuration> 

When I test the pages, error 505 works fine and redirects to the right page, but 404 does not redirect and returns the standard IIS 404 error. I confirmed that the 404 error page is installed on the server in the right place.

I do not see what else I need to do.

+7
iis custom-errors
source share
2 answers

In the end, it worked (helped find this: http://forums.iis.net/t/1173965.aspx ) using:

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> <remove statusCode="500" subStatusCode="100" /> <remove statusCode="500" subStatusCode="-1" /> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="/error_404.asp" responseMode="ExecuteURL" /> <error statusCode="500" prefixLanguageFilePath="" path="/error_500.asp" responseMode="ExecuteURL" /> <error statusCode="500" subStatusCode="100" path="/error_500.asp" responseMode="ExecuteURL" /> </httpErrors> </system.webServer> </configuration> 
+6
source share

I had a similar problem when I had a custom 404 page in / Error / Missing, but it didn’t appear for static files that did not exist, or for folders / directories that had DIDs (but should not be served by MVC). The controller for the Missing page has the following:

  Response.AddHeader("Content-Type","text/html; charset=utf-8"); Response.TrySkipIisCustomErrors = true; Response.StatusCode = (int)HttpStatusCode.NotFound; // 404 

Also, I did not get my own error page if I returned the following to the controller:

 return HttpNotFound(); 

I can change the default IIS errors to a blank page if I installed PassThrough:

 <httpErrors existingResponse="PassThrough" /> 

Changing it to Replace, IIS errors returned by default.

I also had a section in my web.config, but I took it since IIS 8.5, it no longer looks like it.

 <system.web> <customErrors mode="Off"> </system.web> 

So basically I could not get rid of the default IIS messages - single line or more verbose. The httpErrors section is as follows:

 <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> <remove statusCode="404" /> <error statusCode="404" path="/Error/Missing" /> </httpErrors> 

Finally, I came across this question, and I looked at another answer on this question and realized that I could try ResponseMode for each line of errors. I thought this would not be necessary since I have the defaultResponseMode parameter set, but that matters !!

So, if you want to serve a custom 404 page, use this httpErrors module:

 <httpErrors errorMode="Custom"> <remove statusCode="404" /> <error statusCode="404" path="/Error/Missing" responseMode="ExecuteURL" /> </httpErrors> 

I have posted all these details here so that, I hope, it seems that someone else is looking for the same thing as I, I hope this helps!

+2
source share

All Articles