组合web.config文件

时间:2013-07-14 12:44:35

标签: windows include web-config http-status-code-404

如果可以的话,需要一些帮助。

一种是允许.html和.htm文件像某些包含的.asp文件一样,另一种用于自定义404页面。

我尝试过各种各样的变体,但除了单独使用文件之外的所有内容都会给我一个“500 - 内部服务器错误”消息。

web.config 1:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="htmlinc" path="*.html" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
<add name="htminc" path="*.htm" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
</handlers>
</system.webServer>
</configuration>

web.config 2:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/404.htm" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.htm" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/404.htm" />
</customErrors>
</system.web>
</configuration>

1 个答案:

答案 0 :(得分:0)

这应该有效。检查父web.config文件并查找由继承导致的问题。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="htmlinc" path="*.html" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
<add name="htminc" path="*.htm" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
</handlers>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/404.htm" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.htm" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/404.htm" />
</customErrors>
</system.web>
</configuration>