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

日期:2024-02-18 编辑:ucbug下载站

前边给大家讲了在Windows server 2008下配置PHP、MYSQL环境的文章,接下来再说一下IIS7如何正确自定义404错误

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

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

方案1:

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

<system.webServer> 
... 
<httpErrors allowAbsolutePathsWhenDelegated="true"> 
<error statusCode="401" prefixLanguageFilePath="%SystemDrive%inetpubcusterr" path="401.htm" /> 
<error statusCode="403" prefixLanguageFilePath="%SystemDrive%inetpubcusterr" path="403.htm" /> 
<error statusCode="404" prefixLanguageFilePath="%SystemDrive%inetpubcusterr" path="404.htm" /> 
<error statusCode="405" prefixLanguageFilePath="%SystemDrive%inetpubcusterr" 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:Tempcustom404.html" responseMode="File" /> 
</httpErrors> 
</system.webServer> 
</location>

2.重启IIS。

方案2

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

IIS7中的自定义 404页面错误

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

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

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

3. 重启IIS。

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

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

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错误页面。

IIS7中的自定义 404页面错误

8. 点击OK。

相关文章
猜你喜欢