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

256,147

Solution 1

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.

<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.

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.

Solution 2

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.

Solution 3

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

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

Solution 4

When publishing to IIS, by Web Deploy, I just checked the File Publish Options and 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.

Solution 5

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.

Share:
256,147

Related videos on Youtube

Ilya Kogan
Author by

Ilya Kogan

Updated on February 04, 2021

Comments

  • Ilya Kogan
    Ilya Kogan over 3 years

    I'm trying to publish an MVC website as an 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:

    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:

    <?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:

    @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?

    • Jack
      Jack almost 11 years
      Man, your errors throw errors. That some serious ish :)
    • Jakub Konecki
      Jakub Konecki almost 11 years
      I suggest you enable detailed error logging in Management Portal and review the logs on FTP site.
    • drch
      drch almost 11 years
      Is there anything in your layout that may be the culprit?
    • Ilya Kogan
      Ilya Kogan almost 11 years
      @drch No, nothing has changed in the layout since it last worked.
  • Ilya Kogan
    Ilya Kogan almost 11 years
    Setting customErrors to "off" finally showed some real exceptions. I'm investigating them now.
  • drzaus
    drzaus over 9 years
    Since it's resulting in an IIS error, you can customize them too as a fallback a la benfoster.io/blog/aspnet-mvc-custom-error-pages
  • GuiPab
    GuiPab almost 8 years
    My customErrors are "Off", but i continue to see the "Sorry, an error occurred while processing your request." error. Could you help me here? @Ilya Kogan
  • Paul Zahra
    Paul Zahra over 7 years
    +1 simply because setting customerror = off allowed me to see that the error was caused because I had used a website solution as a template for another website and had forgotten to clear out the bin folder, i.e. it was a duplication issue.
  • Aamol
    Aamol about 5 years
    How Oracle come into this picture?