Custom 404 page with <httpErrors> element does not work in IIS 7

I am testing an IIS 7.5 site with managed pipeline mode = "Integrated"

My site is designed for mobile devices and uses well-formed URLs to pass parameters with a minimal set. For example, "mysite.com/bob1234" in this case, "bob1234" is actually a parameter.

In Application.BeginRequest, I process Request.Url.AbsolutePath using a regular expression to determine if the URL is correctly formed.

I wanted to add a Custom 404 page if the user mistakenly uses the ie address mysite.com/boob1234.

<system.web> <customErrors mode="RemoteOnly" defaultRedirect="~/MobileError.aspx"> <error statusCode="404" redirect="404.htm"/> </customErrors> </system.web> 

And although this catches errors when the extension is ".aspx", it does not capture 404 (s) when the handler is not displayed, for example, "/mysite.com/boob1234".

I followed the instructions and added the item to my system.webserver

 <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <httpErrors defaultResponseMode="Redirect" errorMode="DetailedLocalOnly"> <remove statusCode="404" subStatusCode="-1"/> <error statusCode="404" prefixLanguageFilePath="" path="/mobile/MobileError.aspx" responseMode="ExecuteURL"/> </httpErrors> </system.webServer> 

But no iteration of this seems to work. When I uncomment a block, I get 500 errors. And no, there are no problems with my code. I get a 500 error even when I just go to a simple HTML page.

I did an unsuccessful request trace to see what I see.

I get the expected: 404 thrown by IIS Web Core.

Then a few steps later, a CustomerErrorModule is triggered, but with a 500 error. Detailed message

ConfigExceptionInfo: \? \ C: ..... \ MyApp \ web.config (89): This configuration section cannot be used along this path. This happens when the partition is locked by the parent level. The default lock (overrideModeDefault = "Deny") or set explicitly using the location tag with overrideMode = "Deny" or the deprecated AllowOverride = "false".

I tried to approach the .config stack and did not find references to overrideMode = "Deny"

Any help would be awesome. Completely stuck.

Thanks: Dylan

+4
source share
3 answers

Try unlocking the configuration section in applicationhost.config?

 <location path="example.net" overrideMode="Allow"> <system.webServer> <httpErrors> </httpErrors> </system.webServer> </location> 

Link: http://learn.iis.net/page.aspx/124/introduction-to-applicationhostconfig/#Locking

+2
source

This is due to the request life cycle in IIS. In your case, when the handler is not displayed, 404 is recognized before the ASP DLL is even called into the game. For elements that are not explicitly identified in IIS as requiring Asp.Net, the IIS 404 error fires and ignores any directives in Asp.Net. Even if wild-card is used for all extensions, this wild-card is only called if IIS does not detect 404 first. This includes directories and all file extensions that are not explicitly processed by .Net. Therefore, if you try to switch to http://mydomain.com/images/someimage.gif , and this file does not exist, you will not get a .Net 404 error handler. If you change .gif to .aspx , then the handler will start fire. The only method I've seen that responds appropriately to this is to modify all of your 404 handlers in IIS to redirect to the URL file on your local site. It will pass an aspxerror request, but if you put an error? In the url declaration, you can add certain information.

Another thing I tried, although I'm not sure I tried it correctly, is reassigning the file association in IIS. We determined that Asp.Net should process all requests for .gif at some point. The problem I had was that the image did not appear, the Base64 encoding code appeared (I think?). As a last resort, I did not pursue this, since an easier solution was to use IIS user error mappings.

+2
source

Just knock in the dark, try adding this attribute to the httpErrors element:

 existingResponse="PassThrough" 

For instance:

 <httpErrors existingResponse="PassThrough" defaultResponseMode="Redirect" errorMode="DetailedLocalOnly"> 
+1
source

Source: https://habr.com/ru/post/1336535/


All Articles