ElmahR没有发现任何异常

时间:2014-07-14 08:00:02

标签: c# asp.net-mvc-4 elmah elmahr

我试图在我现有的MVC5项目上安装ElmahR。在安装ElmahR之前,我使用Elmah和NLog来处理异常。基于此tutorial我使用nuget包安装了ElmahR

Install-Package ElmahR.Elmah

然后在web.config中,我更改了这一行:

<errorPost targetUrl="http://TARGET_DASHBOARD_URL" sourceId="SOURCE_IDENTIFIER_URI_AS_LISTED_IN_DASHBOARD_CONFIG" secret="SECRET_PASSPHRASE_(SPECIFY_JUST_IN_CASE_OF_ENCRYPTED_POST)" />

<errorPost targetUrl="http://localhost:62335/posterror.axd" sourceId="MyCode" />

下一步我安装了仪表板

Install-Package ElmahR.Modules.Dashboard

并改变了这一行:

<application name="Sample application" sourceId="SomeCode" infoUrl="http://localhost:12345/elmah.axd" testExceptionUrl="http://localhost:12345/elmah.axd/test" />

<application name="WPS" sourceId="MyCode" infoUrl="http://localhost:62335/elmah.axd" testExceptionUrl="http://localhost:62335/elmah.axd/test" />

在HomeController(Index)中,我按throw new exception("Test ElmahR");和Run生成错误。然后我转到http://locahost:62335/elmahr/dashboard并看到没有异常捕获,但如果我看到http://localhost:62335/elmah它捕获了错误&#34; Path&#39; /posterror.axd'找不到&#34;不测试ElmahR。为什么呢?

完整的web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <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" />
      <section name="errorPost" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    </sectionGroup>
    <section name="elmahr" type="ElmahR.Core.Config.SectionHandler, ElmahR.Core" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="MvcSiteMapProvider_IncludeAssembliesForScan" value="WPSWorklog" />
    <add key="MvcSiteMapProvider_UseExternalDIContainer" value="false" />
    <add key="MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" value="true" />
    <add key="elmah.mvc.disableHandler" value="false" />
    <add key="elmah.mvc.disableHandleErrorFilter" value="false" />
    <add key="elmah.mvc.requiresAuthentication" value="true" />
    <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" />
    <add key="webpages:Enabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <customErrors mode="RemoteOnly" defaultRedirect="~/Error">
      <error redirect="~/Error/NotFound" statusCode="404" />
    </customErrors>
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Windows" />
    <authorization>
      <deny users="?" />
    </authorization>
    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
      <providers>
        <clear />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
        <add namespace="MvcSiteMapProvider.Web.Html.Models" />
      </namespaces>
    </pages>
    <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
      <add name="ErrorPost" type="ElmahR.Elmah.ErrorPostModule, ElmahR.Elmah" />
    </httpModules>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
      <remove name="BundleModule" />
      <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
      <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" />
      <add name="ErrorPost" type="ElmahR.Elmah.ErrorPostModule, ElmahR.Elmah" />
      <!--
        You may want to enable the following declaration in order 
        to have your dashboard collecting errors happening inside 
        the dashboard itself (ELMAH is needed and must be properly 
        configured).
        -->
      <!--<add name="ErrorPost" type="ElmahR.Core.ErrorTrapModule, ElmahR.Core" />-->
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      <add name="PostError" verb="POST" path="PostError.axd" type="ElmahR.Core.PostError, ElmahR.Core" />
      <add name="YSOD" verb="GET,HEAD" path="YellowScreenOfDeath.axd" type="ElmahR.Core.YellowScreenOfDeath, ElmahR.Core" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <connectionStrings>
    <add name="WPSWorklogEntities" connectionString="metadata=res://*/Models.WPSWorklog.csdl|res://*/Models.WPSWorklog.ssdl|res://*/Models.WPSWorklog.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=WPSWorklog;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <elmah>
    <!--<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/XMLLog" />-->
    <errorFilter>
      <test>
        <and>
          <equal binding="HttpStatusCode" value="404" type="Int32" />
          <regex binding="Context.Request.ServerVariables['URL']" pattern="/favicon\.ico(\z|\?)" />
        </and>
      </test>
    </errorFilter>
    <security allowRemoteAccess="false" />
    <errorLog type="Elmah.MemoryErrorLog, Elmah" />
    <errorPost targetUrl="http://localhost:62335/posterror.axd" sourceId="MyCode" />
  </elmah>
  <elmahr>
    <application name="WPS" sourceId="MyCode" infoUrl="http://localhost:62335/elmah.axd" testExceptionUrl="http://localhost:62335/elmah.axd/test" />
  </elmahr>
</configuration>

更新1

作为@Wasp的建议,我在system.websystem.webServer注册了Elmah模块和处理程序,但仍未解决问题:

<system.web>
  ...
  <httpHandlers>
    <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
  </httpHandlers>
  ...
</system.web>

<system.webServer>
  ...
  <handlers>
    <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
  </handlers>
  ...
</system.webServer>

1 个答案:

答案 0 :(得分:0)

如果您不使用IIS(完整版或快速版),则可能会遇到此问题,因为我在system.web/httpHandlers中没有看到web.config部分,您将在此处声明丢失posterror.axd 1}}端点。端点位于system.webserver/handlers部分,但需要IIS。你检查过了吗?