Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

.net - IIS7 custom 404 not showing

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 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." (so nothing to do with IE)

<customErrors redirectMode="ResponseRewrite" mode="On" defaultRedirect="/pages/404.aspx" />
</system.web>
<system.webServer>
    <httpErrors  >
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/pages/404.aspx" responseMode="ExecuteURL" />
    </httpErrors>
</system.webServer>

also tried

<httpErrors existingResponse="PassThrough" />

but that just resulted in an empty response.

I have only found one reference to the usefulness of executing the appcmd to test the custom http error handling but here are the results.

C:WindowsSystem32inetsrv>appcmd list config "http://mysite/file.notexist" -section:httpErrors

<system.webServer>
    <httpErrors>
        <error statusCode="401" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="401.htm" />
        <error statusCode="403" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="403.htm" />
        <error statusCode="404" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="404.htm" />
        <error statusCode="405" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="405.htm" />
        <error statusCode="406" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="406.htm" />
        <error statusCode="412" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="412.htm" />
        <error statusCode="500" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="500.htm" />
        <error statusCode="501" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="501.htm" />
        <error statusCode="502" prefixLanguageFilePath="%SystemDrive%inetpubcuster
r" path="502.htm" />
    </httpErrors>
</system.webServer>

which is odd because in iis7 manager the error pages show

404 /pages/404.aspx Execute URL Local

.Net Error Pages shows nothing, though I did have an entry in there.

Question 1 : what steps do I need to take for a completely new asp .net 4 iis7 site to have a custom .net error page for every 404 result ?

Question 2 : why does the .net handler work for .aspx files and nothing else ?

note: set the 404 at server level and the appcmd command then showed the custom 404 in the path, but made no difference to the site failing to showing 404.

So I am guessing it's a red herring.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...