在进行如下带静态文件的自定义404页面配置时,
您可能会收到如下错误(见下图),
500.19 – Internal Server Error
Absolute physical path “driver:\path” is not allowed in system.webServer/httpErrors section in web.config file. Use relative path instead.
根本原因:
当在web.config文件中检测到绝对路径时,就会产生此错误。
目前针对该问题有2种解决方案。
方案1:
1. 在ApplicationHost.config文件中将<system.webServer> <httpErrors>的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。
参考
HTTP Errors <httpErrors>
您可能会收到如下错误(见下图),
500.19 – Internal Server Error
Absolute physical path “driver:\path” is not allowed in system.webServer/httpErrors section in web.config file. Use relative path instead.
根本原因:
当在web.config文件中检测到绝对路径时,就会产生此错误。
目前针对该问题有2种解决方案。
方案1:
1. 在ApplicationHost.config文件中将<system.webServer> <httpErrors>的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。
参考
HTTP Errors <httpErrors>
http://www.iis.net/ConfigReference/system.webServer/httpErrors