在WebForms应用程序(.Net 3.5)中以经典模式使用IIS 7.5(因为我们正在使用SiteCore)时,我们将错误页面定义为
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
现在,对于在请求时未找到的非.Net类型的文件,不会显示自定义错误页面,并返回标准的404状态类型。如果我们使用带有.htm扩展名的自定义错误页面(例如path =“/Error/404.htm”),则会显示该页面!
从我看过的XML是正确的,并且应该适用于非.Net文件类型。我的web.config中没有任何部分。听起来像其他东西SiteCore可能会影响事情-如果您需要更多信息,请告诉我。
最佳答案
404自定义页面-适用于.aspx和非.aspx URL
在GoDaddy共享Windows主机(IIS7 .Net4)上工作
在共享GoDaddy托管中的本地主文件夹上创建404.html或404.aspx文件。
-Web.Config文件-
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="404.html or 404.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
关于asp.net - 自定义404页未针对缺少的ASPX页执行-IIS 7,5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8263552/