C# asp.net mvc中的友好错误页

C# asp.net mvc中的友好错误页,c#,asp.net,asp.net-mvc,asp.net-mvc-4,elmah,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Elmah,我刚刚在我的asp.net mvc应用程序上安装了ELMAH,这个框架记录了所有错误,我可以在页面/ELMAH上看到友好的日志 这正是我需要的,但我需要做点别的 如果由于任何原因引发异常,我希望显示一个友好的页面 elmah仍必须抓住例外情况 我缺少什么来配置 <?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET applicatio

我刚刚在我的asp.net mvc应用程序上安装了ELMAH,这个框架记录了所有错误,我可以在页面/ELMAH上看到友好的日志

这正是我需要的,但我需要做点别的

  • 如果由于任何原因引发异常,我希望显示一个友好的页面
  • elmah仍必须抓住例外情况
  • 我缺少什么来配置

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <configSections>
        <sectionGroup name="elmah">
          <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
          <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
          <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
          <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
        </sectionGroup>
      </configSections>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
        <add key="ClientId" value="ss" />
        <add key="ClientSecret" value="xx" />
        <add key="elmah.mvc.disableHandler" value="false" />
        <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
        <add key="elmah.mvc.requiresAuthentication" value="false" />
        <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
        <add key="elmah.mvc.allowedRoles" value="*" />
        <add key="elmah.mvc.allowedUsers" value="*" />
        <add key="elmah.mvc.route" value="elmah" />
      </appSettings>
      <system.web>
        <httpHandlers>
          <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
        </httpHandlers>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <httpModules>
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
          <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
        </httpModules>
      </system.web>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <!--Used by app for SharePoint-->
            <binding name="secureBinding">
              <security mode="Transport" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <protocolMapping>
          <add binding="basicHttpBinding" scheme="https" bindingConfiguration="secureBinding" />
        </protocolMapping>
      </system.serviceModel>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules>
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
          <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
        </modules>
      </system.webServer>
      <elmah>
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
      </elmah>
    </configuration>
    
    
    
    您缺少以下部分:

    
    

    这将在异常未处理时将用户重定向到URL。您可以通过编写响应此URL的操作方法来显示用户友好的页面,也可以使用静态文件。ELMAH仍将记录异常。

    您应该让控制器返回相应的状态代码。如果不执行任何操作,则发生错误时将返回200个状态代码。
    <system.web>
      <customErrors defaultRedirect="~/error" mode="RemoteOnly"/>
    </system.web>