asp.net - 自定义404页未针对缺少的ASPX页执行-IIS 7,5

标签 asp.net iis iis-7 error-handling web-config

在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/

相关文章:

asp.net - 使用 IIS6 重写 HttpModule URL,不带无扩展名 URL

css - 部署后在 Intranet 上访问时,MVC5 Web 应用程序看起来不正确

asp.net - Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) 在 ASP.Net 项目中返回空字符串

c# - HttpWebRequest DefaultNetworkCredentials 给出错误 401

asp.net - 直接在包含ASP.NET中内容控件的内容页面中仅允许内容控件

asp.net-mvc - 为特定 Controller ASP.Net Core MVC 设置请求超时

jquery - 我只从 asp.net Razor View 中获取 jQuery 中的第一个 id

c# - FtpWeb请求 : The remote server returned an error: (530) Not logged in

wcf - 每个配置文件 'DbProviderFactories'部分只能出现一次

c# - 网站在 MVC Controller 上请求 "Authentication Required",而不是其他 Controller