IIS7自定义404不显示 [英] IIS7 custom 404 not showing

查看:313
本文介绍了IIS7自定义404不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建了一个新的IIS7的网站与综合型.NET 4.0应用程序池。

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

网址用的.aspx结尾确实显示自定义的404别的使蓝色服务器错误页面 HTTP错误404.0 - 未找到 您正在寻找已被删除的资源,有其名称更改,或者暂时不可用。 (所以无关IE)

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>

也试过

<httpErrors existingResponse="PassThrough" />

但只是造成了一个空的响应。

but that just resulted in an empty response.

我只找到了一个参照执行APPCMD测试自定义HTTP错误处理的有效性,但这里的结果。

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:\Windows\System32\inetsrv>appcmd list config "http://mysite/file.notexist" -section:httpErrors

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

这是奇怪的,因为IIS7管理器中的错误页面显示

which is odd because in iis7 manager the error pages show

404 /pages/404.aspx Execute URL Local

.NET错误页显示什么,虽然我没有在那里有一个条目。

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

问题1:哪些步骤,我需要采取一个全新的ASP.NET 4 IIS7的网站有一个自定义的.NET错误页每404结果

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 ?

问题2:为什么在.NET处理工作.aspx文件,并没有别的

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

请注意:设置404服务器级别和APPCMD命令则表现在路径的自定义的404,但并未影响到该网站未能显示出404

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.

推荐答案

答案是使用

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

和不要有任何的System.Web的customErrors

and not to have any system.web customErrors

这个工作为的.aspx和非的.aspx请求。

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

奇怪的是这个组合没有拿出任何的博客文章和StackOverflow的答案,我已经调查了,这只是运气我试了一下。

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.

这篇关于IIS7自定义404不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆