C# 如何设置 web.config 文件以显示完整的错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11665322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 18:43:13  来源:igfitidea点击:

How to set web.config file to show full error message

c#asp.netasp.net-mvc-3web-config

提问by King Kong

I deployed my MVC-3 application on windows Azure. But now when I am requesting it through staging urlit shows me (Sorry, an error occurred while processing your request.). Now I want to see the full error message, by default it is hiding that because of some security reasons. I know that we can do this through web.config file. But how?

我在 Windows Azure 上部署了我的 MVC-3 应用程序。但是现在当我通过staging url它请求它时,它会显示我(抱歉,处理您的请求时出错。)。现在我想查看完整的错误消息,由于某些安全原因,默认情况下它会隐藏该消息。我知道我们可以通过 web.config 文件来做到这一点。但是如何?

采纳答案by jim tollan

not sure if it'll work in your scenario, but try adding the following to your web.configunder <system.web>:

不确定它是否适用于您的场景,但请尝试将以下内容添加到您的web.configunder <system.web>

  <system.web>
    <customErrors mode="Off" />
  ...
  </system.web>

works in my instance.

在我的例子中工作。

also see:

另见:

CustomErrors mode="Off"

自定义错误模式=“关闭”

回答by Sandrino Di Mattia

If you're using ASP.NET MVC you might also need to remove the HandleErrorAttributefrom the Global.asax.cs file:

如果您使用的是 ASP.NET MVC,您可能还需要从 Global.asax.cs 文件中删除HandleErrorAttribute

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
}

回答by Meer

This can also help you by showing full details of the error on a client's browser.

这也可以通过在客户端浏览器上显示错误的完整详细信息来帮助您。

<system.web>
    <customErrors mode="Off"/>
</system.web>
<system.webServer>
    <httpErrors errorMode="Detailed" />
</system.webServer>