asp.net - 无法为 Elmah 配置邮件

标签 asp.net elmah

我有以下配置文件片段

<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>
 <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com"
           port="587"
           userName="example@gmail.com"
           password="password" />
        </smtp>
      </mailSettings>
  </system.net>
 <elmah>
    <errorMail
              from="example1@gmail.com"
              to="example2@gmail.com"
              sync="true"
              smtpPort="0"
              useSsl="true"
            />
  </elmah>

我已经用适当的东西替换了 example1 等。现在,我有以下问题:-
1)为什么它不工作?
2)我如何调试它?
3)我需要一种永久的方式来调试 web.config 或至少一些代码,当配置文件中出现错误时,这些代码会发出一些错误消息。

最佳答案

尝试这个:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <!--ELMAH-->
        <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>
    <elmah>
        <security allowRemoteAccess="1"/>   
        <!-- set the smtpPort attribute to "0". Doing so will cause ELMAH to use the port defined per the <system.net> settings -->
        <errorMail from="example1@gmail.com" to="example2@gmail.com" subject="ERROR(test):" async="false" smtpPort="0" useSsl="true" />
    </elmah>
    <!--System.net Mail setup-->
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="network">
                <network host="smtp.gmail.com" port="587" userName="example1@gmail.com" password="..." />
            </smtp>
        </mailSettings>
    </system.net>
    <appSettings>
    ...
 </appSettings>
    <connectionStrings>
        ...     
    </connectionStrings>
    <system.web>
        <compilation debug="true">
            <assemblies>
                ...
        </compilation>
        <customErrors mode="Off"/>
        ...
        <httpHandlers>
            ...
            <!--ELMAH-->
            <add verb="POST,GET,HEAD" path="MyErrorPage/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>            
        </httpHandlers>
        <httpModules>
            ...
            <!-- ELMAH: Logging module -->
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
            <!-- <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> -->
            <!--<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>-->
        </httpModules>
        <httpRuntime maxRequestLength="458292"/>
        <authentication mode="Forms">
            ...
        </authentication>
    ...
    </system.web>
    <location path="MyErrorPage.aspx">
        <system.web>
            <authorization>
                <allow users="?"/>
            </authorization>
        </system.web>
    </location> 
    <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
            ...
            <!-- ELMAH-->
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> 
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
        </modules>
        <handlers>
            ...
            <!--ELMAH-->
            <add name="Elmah" verb="POST,GET,HEAD" path="MyErrorPage/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>           
        </handlers>
    </system.webServer>
    <runtime>       
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            ...
        </assemblyBinding>
    </runtime>
    <location path="MyErrorPage/elmah.axd">
        <system.web>
      <authorization>
        <deny users="?"/>
        <allow users="?"/>
      </authorization>
        </system.web>
    </location>  
</configuration>

关于asp.net - 无法为 Elmah 配置邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7926951/

相关文章:

c# - 在 mac 中没有找到匹配命令 "dotnet-aspnet-codegenerator"asp.net core 2.1 项目的可执行文件

c# - 在 CSS 中使用 C# 变量

.net-core - 如何为控制台应用程序设置 ElmahCore?

asp.net - 隐藏表单值

asp.net-mvc - Serilog、Elmah 或两者都适用于 ASP.NET MVC 项目?

c# - 如何使用 @Model (TimeSpan) 在 Razor 中使用三元运算符?

c# - MS Chart X 轴标签重复 - 显示单个项目的多个点 [Range Bar]

Javascript正则表达式将图像文件发送到asp.net中的FileUpload控件

asp.net-mvc - asp.net mvc : What makes error. cshtml 运行(并且在此过程中未登录到 elmah)

sqlite - ELMAH 1.2 无法加载文件或程序集 'System.Data.SQLite' 或其依赖项之一