晓木虫
学术数据库客户端

IIS7自定义404页面返回500错误的解决方案

 找回密码
 注册会员

QQ登录

微信登录

IIS7自定义404页面返回500错误的解决方案

跳转到指定楼层
一般在IIS6下,大家只要在错误页选择自己做的404错误,就可以了,但是IIS7.5却返回500,还有的同学返回200,这是怎么回事?查了资料发现还是微软搞的鬼。

微软给出了两个解决方案,不过我自己使用第一个解决方案没有成功,我是使用的第二个

方案1:

1. 在ApplicationHost.config文件中将 的allowAbsolutePathsWhenDelegated设置为”true”。

<system.webServer>
...
<httpErrors allowAbsolutePathsWhenDelegated="true">
<error statusCode="401" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="401.htm" />
<error statusCode="403" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="403.htm" />
<error statusCode="404" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="404.htm" />
<error statusCode="405" prefixLanguageFilePath="%SystemDrive%\inetpub\custerr" path="405.htm" />
....
</httpErrors>
</system.webServer>
</location>
<location path="Default Web Site">
<system.webServer>
... ...
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="E:\Temp\custom404.html" responseMode="File" />
</httpErrors>
</system.webServer>
</location>

2.重启IIS。

方案2

1. 在IIS Manager中,找到Features Views->Management Area,双击”Feature Delegation”。选择Error Pages并单击Read Only,如下图。



2. 在C:\inetpub\wwwroot或您的任何网页应用程序的物理目录下,打开web.config文件,移除以下部分。

<handlers accessPolicy="Read, Script" />
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path=" E:\Temp\error404.html " responseMode="File" />
</httpErrors>

如果在config文件中没有其他配置,您可以直接删除由IIS为delegation Read/Write生成的web.config文件。

3. 重启IIS。

如何在IIS7中进行自定义404页面设置的步骤:

1. 创建一个名为custom404.html的文件,并保存至您的网页目录(一般情况下为c:\inetpub\wwwroot)。

2. 打开Internet Information Services (IIS) Manager。

3. 在Connections窗口内(左边),展开相关节点至某个您想要进行自定义错误配置的站点,并选定该站点。

4. 在中间窗口的底部,单击Features View。

5. 在中间窗口,双击Error Pages。

6. 双击Status Code 404。

7. 在Edit Custom Error Page对话框中,

a. 在”Insert content from static file into the error response”域中输入物理路径。当出现找不到页面的情况时,就会返回http 404错误并显示自定义的404错误页面。

b. 在”Exectute a URL on this site”域中,输入绝对路径。在本实例中,输入/custom404.html。当出现找不到页面的情况时,就会返回http 200错误并显示自定义的404错误页面。



8. 点击OK。

IIS7自定义404页面返回500错误的解决方案
谢谢您的分享!
好东西一定要看看!
大家都不容易!
论坛有你更精彩!
谢谢您的分享!
谢谢您的分享!
论坛有你更精彩!
好东西一定要看看!
好东西一定要看看!
论坛有你更精彩!
大家都不容易!
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则  | 请遵守晓木虫管理条例,不得违反国家法律法规

返回顶部