asp.net-mvc “处理您的请求时发生异常。此外,在执行自定义错误页面时发生了另一个异常……”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17274481/
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-09-08 02:58:06  来源:igfitidea点击:

"An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page..."

asp.net-mvcasp.net-mvc-4web-configserver-error

提问by Ilya Kogan

I'm trying to publish an MVC website as an Azure webrole.

我正在尝试将 MVC 网站发布为 Azure webrole。

When I run it locally, everything works fine.

当我在本地运行它时,一切正常。

But once I publish it to Azure and surf to some MVC action, I get this error:

但是一旦我将它发布到 Azure 并浏览到一些 MVC 操作,我就会收到此错误:

Server Error in '/' Application.

Runtime Error

Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.

“/”应用程序中的服务器错误。

运行时错误

描述:处理您的请求时发生异常。此外,在为第一个异常执行自定义错误页面时发生了另一个异常。请求已终止。

I don't understand how the error handler can encounter an exception, because errors are handled in the default way:

我不明白错误处理程序如何遇到异常,因为错误以默认方式处理:

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

This is my web.config:

这是我的 web.config:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
        <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

This is Error.cshtml:

这是 Error.cshtml:

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Error";
}

<h2>
    Sorry, an error occurred while processing your request.
</h2>

What can cause this exception, and why can't I reproduce it locally?

什么会导致此异常,为什么我不能在本地重现它?

回答by viperguynaz

First, set customErrors = "Off" in the web.config and redeploy to get a more detailed error message that will help us diagnose the problem. You could also RDP into the instance and browse to the site from IIS locally to view the errors.

首先,在 web.config 中设置 customErrors = "Off" 并重新部署以获取更详细的错误消息,以帮助我们诊断问题。您还可以 RDP 进入实例并从本地 IIS 浏览到站点以查看错误。

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

First guess though - you have some references (most likely Azure SDK references) that are not set to Copy Local = true. So, all your dependencies are not getting deployed.

首先猜测 - 您有一些未设置为 Copy Local = true 的引用(很可能是 Azure SDK 引用)。因此,您的所有依赖项都没有得到部署。

Get to the detailed error first and update your question.

首先获取详细错误并更新您的问题。

UPDATE: A second option now available in VS2013 is Remote Debugging a Cloud Service or Virtual Machine.

更新:VS2013 中现在可用的第二个选项是Remote Debugging a Cloud Service or Virtual Machine

回答by SharpC

I wasn't using Azure, but I got the same error locally. Using <customErrors mode="Off" />seemed to have no effect, but checking the Application logs in Event Viewer revealed a warning from ASP.NET which contained all the detail I needed to resolve the issue.

我没有使用 Azure,但我在本地遇到了同样的错误。使用<customErrors mode="Off" />似乎没有效果,但检查事件查看器中的应用程序日志显示来自 ASP.NET 的警告,其中包含解决问题所需的所有详细信息。

回答by Conner

If you add this to your web.config transformation file, you can also set certain publish options to have debugging enabled or disabled:

如果您将此添加到您的 web.config 转换文件,您还可以设置某些发布选项以启用或禁用调试:

<system.web>
    <customErrors mode="Off" defaultRedirect="~/Error.aspx" xdt:Transform="Replace"/>
</system.web>

回答by Mike Godin

I had this problem with only with redirectMode="ResponseRewrite"(redirectMode="ResponseRedirect"worked fine) and none of the above solutions helped my resolve the issue. However, once I changed the server's application pool's "Managed Pipeline Mode" from "Classic" to "Integrated" the custom error page appeared as expected.

我只有redirectMode="ResponseRewrite"redirectMode="ResponseRedirect"工作正常)遇到了这个问题,并且上述解决方案都没有帮助我解决问题。但是,一旦我将服务器的应用程序池的“托管管道模式”从“经典”更改为“集成”,自定义错误页面就会按预期出现。

回答by ASPaiva

When publishing to IIS, by Web Deploy, I just checkedthe File Publish Optionsand executed. Now it works! After this deploy the checkboxes do not need to be checked. I don't think this can be a solutions for everybody, but it is the only thing I needed to do to solve my problem. Good luck.

通过 Web Deploy 发布到 IIS 时,我只是检查文件发布选项并执行。现在它起作用了!在此部署之后,不需要选中复选框。我不认为这可以成为每个人的解决方案,但这是我唯一需要做的事情来解决我的问题。祝你好运。

回答by user3597243

You can use Oracle.ManagedDataAccess.dll instead (download from Oracle), include that dll in you project bin dir, add reference to that dll in the project. In code, "using Oracle.MangedDataAccess.Client". Deploy project to server as usual. No need install Oracle Client on server. No need to add assembly info in web.config.

您可以改用 Oracle.ManagedDataAccess.dll(从 Oracle 下载),将该 dll 包含在您的项目 bin 目录中,在项目中添加对该 dll 的引用。在代码中,“使用 Oracle.MangedDataAccess.Client”。像往常一样将项目部署到服务器。无需在服务器上安装 Oracle 客户端。无需在 web.config 中添加程序集信息。