小编Kao*_*aos的帖子

web.config/Global.asax中的自定义错误处理不处理不存在的目录

问题是:为什么自定义错误处理不适用于不存在的路径/目录?

更新了固定代码(感谢大家为您输入):

*更新了web.config和global.asax *的代码

<httpErrors errorMode="Custom">
        <remove statusCode="500" subStatusCode="-1" />
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/*****.aspx" responseMode="ExecuteURL" />
        <error statusCode="500" subStatusCode="-1"  prefixLanguageFilePath="" path="/*****.aspx"  responseMode="ExecuteURL"/>
    </httpErrors>

    added this to the global.asax to stop IIS from handling my 500 errors
    after @Kev's suggestions IIS handled my 500's these lines fixed that
    HttpApplication myApplication = new HttpApplication();
    myApplication.Response.TrySkipIisCustomErrors = true;
Run Code Online (Sandbox Code Playgroud)

我们有一个站点设置自定义错误处理web.configglobal.asax(设置如下图所示).我们能够毫无问题地处理所有404和500.错误被记录Application_Errorglobal.asax,记录到数据库然后使用HttpContext我们设置状态代码并用于Server.Transfer()将用户移动到相应的错误页面(重定向导致302,并伤害搜索引擎优化).

问题是当用户键入http://www.example.com/whatever空白页面时显示在Firefox中,而在IE中显示IE 404页面.Firebug没有显示被激活的状态代码,当我调试解决方案时,我没有设置任何断点global.asax.奇怪的是,用户可以输入 …

.net c# asp.net iis web-config

8
推荐指数
1
解决办法
4万
查看次数

标签 统计

.net ×1

asp.net ×1

c# ×1

iis ×1

web-config ×1