IIS7 custom 404 not showing

后端 未结 4 1402
-上瘾入骨i
-上瘾入骨i 2020-11-28 07:59

created a new IIS7 web site with Intergrated .net 4.0 app pool.

URLs ending with .aspx do show custom 404 anything else gives the blue server error page \"HTTP Error

相关标签:
4条回答
  • 2020-11-28 08:24
    <httpErrors existingResponse="PassThrough" />
    

    worked for me in IIS 7 (Windows Server 2008 R2).

    My problem was I had this in my web.config, but in a <location>. Moving it to the root <system.webServer> fixed it.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        ...
        <system.webServer>
            ...
            <httpErrors existingResponse="PassThrough" />
        </system.webServer>
    </configuration>
    
    0 讨论(0)
  • 2020-11-28 08:27

    For IIS7 onwards, go with httpErrors only, as per rob's answer: https://stackoverflow.com/a/6661699

    Just to add, unless you need/want to use ASP.NET to render your error page, I would recommend using static HTML files to remove the dependency on ASP.NET. Just be sure to omit any leading forward slash and use backslashes for the rest of the path, e.g.

    <error statusCode="404" prefixLanguageFilePath="" path="pages\404.html" responseMode="File" />
    

    Set responseMode="File" to retain the correct status code.

    0 讨论(0)
  • 2020-11-28 08:35

    I was having this issue with my web app and I got it resolved by commenting out the redirect line:

        <httpErrors>
            <remove statusCode="403" subStatusCode="-1" />
            <!--<error statusCode="403" prefixLanguageFilePath="" path="C:\inetpub\redirectSItoHttps.htm" responseMode="File" />-->
        </httpErrors>
    

    On IIS, the allowAbsolutePathsWhenDelegated (on Configuration Editor --> system.webServer/httpErrors) was locked and I can't change the value false to true.

    0 讨论(0)
  • 2020-11-28 08:36

    answer was to use

        <httpErrors existingResponse="Replace" errorMode="Custom">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/pages/404.aspx?he" responseMode="ExecuteURL" />
        </httpErrors>
    

    and not to have any system.web customErrors

    this worked for both .aspx and non .aspx requests.

    bizarrely this combination did not come up in any of the blog posts and stackoverflow answers I had investigated, it was just luck I tried it.

    0 讨论(0)
提交回复
热议问题