asp.net - 在 IIS 7 上浏览新部署的 MVC 应用程序时出错 : Http 500 and custom errors not set

标签 asp.net asp.net-mvc iis iis-7 web-deployment

我的 MVC 项目根目录中的 web.config 文件中确实存在自定义错误。

<customErrors mode="On" defaultRedirect="~/Error">
  <error statusCode="403" redirect="~/Error/UnauthorizedAccess" />
  <error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>

但是,当我在 IIS 7 中部署该项目时,任何浏览 Web 应用程序的尝试都会在浏览器中产生此错误:

Description: An application error occurred on the server. The current custom error 
settings for this application prevent the details of the application error from being 
viewed remotely (for security reasons). It could, however, be viewed by browsers 
running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote 
machines, please create a <customErrors> tag within a "web.config" configuration file 
located in the root directory of the current web application. This <customErrors> 
tag should then have its "mode" attribute set to "Off".

    <!-- Web.Config Configuration File -->

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


Notes: The current error page you are seeing can be replaced by a custom error page by 
modifying the "defaultRedirect" attribute of the application's <customErrors> configuration 
tag to point to a custom error page URL.    

    <!-- Web.Config Configuration File -->

    <configuration>
        <system.web>
            <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
        </system.web>
    </configuration>

在我的应用程序中,我处理了错误并记录了它们,还向一些团队成员发送了电子邮件。当我在 Visual Studio 或本地运行应用程序时,所有这些都有效。但是当我浏览这个新部署的应用程序时,没有创建任何日志,也没有发送任何电子邮件。

更新

有趣的是,它确实进入了我的应用程序的错误处理程序。我知道这一点是因为地址栏上写着:

http://10.1.17.43/MyApp/Error?aspxerrorpath=/MyApp

其中 Error 是我的应用程序中处理所有异常的 Controller (ErrorController)。

最佳答案

首先,我会尝试设置 <customErrors mode="Off" /> ,只是为了查看潜在的错误消息是什么。这可能是某种配置错误。

由于正在调用应用程序的错误页面,因此错误页面本身很可能发生错误。设置<customErrors mode="Off" />会让您看到错误是什么。

关于asp.net - 在 IIS 7 上浏览新部署的 MVC 应用程序时出错 : Http 500 and custom errors not set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551157/

相关文章:

asp.net - 表单例份验证适用于开发服务器,但不适用于生产服务器(相同的 SQL 数据库)

asp.net - 为什么我不能使用 NuGet 删除包?

c# - MVC C# - AJAX 将 2 个模型传递给 Controller

asp.net - Azure 虚拟机是否支持 TCP 套接字?

asp.net - 在自主机模式下获取当前的 owin 上下文

asp.net-mvc - 您可以从其项目文件夹运行 ASP.NET MVC 应用程序吗?

asp.net - MVC 6 vNext 显示名称属性不起作用

asp.net - 处理 “Invalid Postback or Callback Argument”错误

c# - 什么是 View 引擎?它实际上做了什么?

c# - 如果可能,将多个 if 条件合并为单个 LINQ 语句