Sve*_*ang 10 .net vb.net asp.net elmah
首先,我发现你可以捕获它并将其记录在catch中,但这不会发送电子邮件.然后我发现了使用这门Error Signal课程.这有用,但是从阅读中看不出来的是,它将错误视为正常,因此当我发出错误信号时,它仍会转到自定义错误页面,我不希望这种情况发生.
我想要做的是捕获该错误,记录它,发送电子邮件,但保持在页面上发生错误,以便我可以提供特殊反馈.我不希望它转到自定义错误页面.
我怎么能做到这一点?
编辑:这是我拥有的,它将我重定向到自定义错误页面.
Try
smtpClient.Send(mailMessage)
Catch smtpEx As SmtpException
errorSignal.FromCurrentContext().Raise(smtpEx)
Catch ex As Exception
errorSignal.FromCurrentContext().Raise(ex)
End Try
Run Code Online (Sandbox Code Playgroud)
编辑:发布涉及Elmah的web.config部分(除了连接字符串hah)并且我的Global.asax文件中没有涉及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>
<elmah>
<security allowRemoteAccess="1" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Elmah.Sql" applicationName="Web Main" />
<errorMail from="xxx" to="xxx" cc="xxx" subject="main website error" async="true" smtpPort="25" smtpServer="xxx" userName="xxx" password="xxx" />
<errorFilter>
<test>
<and>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<regex binding="FilterSourceType.Name" pattern="mail" />
</and>
</test>
</errorFilter>
</elmah>
<httpHandlers>
<add verb="POST,GET,HEAD" path="errors/admin/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Elmah" path="elmah/admin/elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath="" path="/errors/error.asp" responseMode="ExecuteURL" />
<error statusCode="404" prefixLanguageFilePath="" path="/global/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<location path="errors/admin/elmah.axd">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)
jon*_*ezy 20
以下应该工作(我做你正在谈论的完全相同的事情)
try {
// do something
} catch (Exception ex) {
Elmah.ErrorSignal.FromCurrentContext().Raise(ex); // logs and sends the error through elmah
// write a message to the user
}
Run Code Online (Sandbox Code Playgroud)
如果你想要一个很好的框架来显示消息,你可以查看smokesignals(免责声明:这是我的工作)