IIS Configuration for 404.13 User Error

I have a simple ASP.NET MVC 3 website hosted in IIS 7.0 and am having difficulty displaying a custom HTTP error page for the 404.13 http status code.

I have the following configuration in Web.Config

<system.web> <httpRuntime maxRequestLength="2048"/> <customErrors mode="Off"/> </system.web> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <clear/> <error statusCode="404" subStatusCode="-1" path="/home/showerror" responseMode="ExecuteURL" /> <error statusCode="404" subStatusCode="13" path="/home/showerror" responseMode="ExecuteURL" /> </httpErrors> <security> <requestFiltering> <requestLimits maxAllowedContentLength="1048576"/> </requestFiltering> </security> </system.webServer> 

When I go to a page that does not exist, my error page displays correctly. However, if I upload a file larger than 1 MB, I get a blank 404 response. The URL never runs. If I changed responseMode to Redirect then the user will be redirected correctly.

+8
iis-7 asp.net-mvc-3
source share
2 answers

The user error does not appear, most likely due to the locking function of the configuration system. Try the following command to unlock it:

 %windir%\System32\inetsrv\appcmd unlock config -section:system.webserver/httperrors 

After playing several days with the RequestFilters and CustomError pages, it finally worked for me.

+3
source share

I had the same issue with IIS 7.5 in integrated mode.

In the end, I refused to handle the error in the web.config method and instead moved the error detection and handling to Application_EndRequest:

Add the following to your global.asax file:

If you do not have global.asax (MVC), you can add a page error instead.

 Protected Sub Application_EndRequest(ByVal sender As Object, ByVal e As System.EventArgs) Dim context As HttpContext = HttpContext.Current.ApplicationInstance.Context If Not IsNothing(context) Then If context.Response.StatusCode = 404 And context.Response.SubStatusCode = 13 Then context.Response.ClearHeaders() context.Server.Transfer("~/errors/404.13.aspx", False) End If End If End Sub 
+1
source share

All Articles