Elmah不使用MVC 3的gmail

本文关键字:gmail MVC Elmah | 更新日期: 2023-09-27 18:10:44

我使用ELMAH为我的MVC 3应用程序与Gmail。关于如何做到这一点,我使用了几个参考资料,包括这个StackOverflow问题,它涉及多个修复

我仍然无法确定为什么我没有收到elmah的电子邮件。我正试图通过在我正在调用的代码中抛出NullReferenceException来测试这一点。

我的网页。配置如下:

     <configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
    <sectionGroup name="elmah">
      <section name="errorMail" requirePermission="false"  type="Elmah.ErrorMailSectionHandler, Elmah"/>
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
    </sectionGroup>
  </configSections>
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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"/>
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
    </httpHandlers>
    <httpModules>
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
    </httpModules>
    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
     <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
      </pages>
      </system.web>
      <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" port="587" userName="username@gmail.com" password="myPassword"/>
      </smtp>
    </mailSettings>
    </system.net>
    <elmah>
    <errorMail   from="fromAddress@gmail.com" to="toAddress@gmail.com" subject="Error" async="true" smtpPort="587"       useSsl="true"/>
    </elmah>
    <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
      <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode"    type="System.Web.HttpNotFoundHandler" />
      <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd"      type="Elmah.ErrorLogPageFactory, Elmah"/>
    </handlers>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </modules>
    </system.webServer>
    </configuration>

对于为什么这可能不工作有什么想法吗?

Elmah不使用MVC 3的gmail

EDIT:这在其他ELMAH配置中可能不一定正确,但您可能想要尝试一下。此外,我知道system.net邮件设置上的enableSSL属性在。net 4.0中是新的-你可能想在该部分添加enableSSL=true,因为GMail确实使用SSL连接。

当比较你的设置和其他ELMAH配置时,看起来你把你的主机配置属性和其他一些设置从你的ELMAH设置中删除了。我不认为ELMAH会查看system.net邮件设置,而是查看它自己的errorMail标签

:

<elmah>
    <errorMail 
      from="fromAddress@gmail.com"
       to="toAddress@gmail.com"
       subject="Error"
       async="true"
       smtpPort="587"
       useSsl="true"/>
    </elmah>

应该改成:

<elmah>
    <errorMail 
      from="fromAddress@gmail.com"
       to="toAddress@gmail.com"
       subject="Error"
       async="true"
       smtpPort="587"
       useSsl="true"
       host="smtp.gmail.com"
       userName="username@gmail.com"
       password="myPassword"/>
    </elmah>