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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....