IIS7 上托管的 ASP.NET 应用程序忽略自定义错误并回退到 IIS 错误

6

本文介绍了IIS7 上托管的 ASP.NET 应用程序忽略自定义错误并回退到 IIS 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 C# Web 表单 ASP.NET 4.0 Web 应用程序,由于某种原因,我的 web.config 的 system.web 部分中定义的自定义错误被完全忽略,它会回退 IIS 错误.

I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ignored and it will fall back the IIS errors.

这完全被忽略了

  <system.web>
    <customErrors mode="On">
      <error statusCode="500" redirect="~/Error" />
      <error statusCode="404" redirect="~/404" />
      <error statusCode="403" redirect="~/Error" />
    </customErrors>
  </system.web>

这部分接管

  <system.webServer>
    <httpErrors>
      <!--<clear />-->
      <remove statusCode="500" subStatusCode="-1" />
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" subStatusCode="-1" path="/App1/404" responseMode="Redirect" />
      <error statusCode="500" prefixLanguageFilePath="" path="/App1/Error" responseMode="Redirect" />
    </httpErrors>
  </system.webServer>

这将是一个小小的不便,除了它回退到 IIS 原生而不是我的应用程序这一事实之外,它完全绕过 Elmah 正确记录我的 404 异常.

This would be a minor inconvenience except that by the fact it falls back to IIS native instead of my application it completely circumvents Elmah logging my 404 exceptions correctly.

为了避免任何此类建议,我只在 customErrors 停止工作后添加了 httpErrors 配置,所以我会得到任何东西.

Just to avoid any suggestions of such I only added the httpErrors configuration after customErrors stopped working so I would have anything.

推荐答案

要禁用必须设置的 IIS 错误消息

To disable the IIS error messages you have to set

  Response.TrySkipIisCustomErrors = true;

在您的错误页面中.之后,您的错误消息应该没有问题地显示.

in your error page. After that, your Error messages should show without problem.

这篇关于IIS7 上托管的 ASP.NET 应用程序忽略自定义错误并回退到 IIS 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Func&lt;string,string&gt; 有什么区别?和委托?
What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)...
2023-11-11 C#/.NET开发问题
3

ASP.NET MVC 中的 &lt;%: 和 &lt;%= 有什么区别?
What is the difference between lt;%: and lt;%= in ASP.NET MVC?(ASP.NET MVC 中的 lt;%: 和 lt;%= 有什么区别?)...
2023-11-10 C#/.NET开发问题
0

标签系统的 linq 查询 - 搜索多个标签
linq query for tag system - search for multiple tags(标签系统的 linq 查询 - 搜索多个标签)...
2023-11-10 C#/.NET开发问题
0

论坛标签.实施它们的最佳方法是什么?
Forum tags. What is the best way to implement them?(论坛标签.实施它们的最佳方法是什么?)...
2023-11-10 C#/.NET开发问题
1

html 脚本标签未使用类型 javascript &lt;script type=&quot;text
html script tag not using type javascript lt;script type=quot;text/htmlquot;gt;?(html 脚本标签未使用类型 javascript lt;script type=quot;text/htmlgt;gt;?)...
2023-11-10 C#/.NET开发问题
6

ASP.NET 控件到 HTML 标记等效
ASP.NET Control to HTML tag equivalent(ASP.NET 控件到 HTML 标记等效)...
2023-11-10 C#/.NET开发问题
32