发布后未触发 application_error 事件

发布于 2024-11-25 11:46:19 字数 1039 浏览 0 评论 0原文

我知道这个问题已经被问过很多次了,但我无法从这些帖子中得到解决。

我已经在 Global.asax 文件中实现了 Application_error 方法来记录所有未处理的异常并发送电子邮件。在 Visual Studio 上运行时效果非常好,但是一旦我将其发布到测试服务器,Application_event 就会停止触发。不会在文本文件中记录任何日志条目,也不会发送电子邮件。

PrecompiledApp.config 文件位于根目录中,App_global.asax.compiled、App_global.asax.dll 位于 bin 文件夹中。我发布网站后,Global.asax 文件不存在。

我尝试删除 PrecompiledApp.config 文件,但它不起作用。 我尝试将 Global.asax 文件添加到根目录,但不起作用。 我已经尝试过在 web.config 文件中使用

   <customErrors mode="Off"  /> 

   <customErrors mode="On" defaultRedirect="Error Page.aspx" /> 

......没有任何效果。

我在页面的Page_load中添加了一行:

    Response.Write("<br/>ApplicationInstance: " +  Context.ApplicationInstance.GetType().FullName);

It returns ApplicationInstance: ASP.global_asax,根据帖子应该返回。 那么为什么该事件没有触发呢?

请帮忙!!!

谢谢!!!

**[编辑] ....我在 Global.asax 文件的 Session_start 事件中添加了一行代码,它起作用了。这意味着 Global.asax 已成功部署。但是为什么发生错误时 Application_error 事件不会被执行呢?有什么想法吗?

I know this has been asked a lot of times, but I could not get things working from those posts.

I have implemented Application_error method in Global.asax file to log and send email for all unhandled exceptions. This works perfectly fine when running on Visual Studio, but as soon as I publish it to the test server, the Application_event stops firing. No log entry is made to the text file and no email is sent.

PrecompiledApp.config file is present in the root directory, along with App_global.asax.compiled, App_global.asax.dll in the bin folder. Global.asax file is not present after I publish the website.

I have tried removing PrecompiledApp.config file, but it doesn't work.
I have tried adding Global.asax file to the root directory, but doesn't work.
I have tried with

   <customErrors mode="Off"  /> 

and

   <customErrors mode="On" defaultRedirect="Error Page.aspx" /> 

in web.config file....nothing works.

I added a line to Page_load of a page:

    Response.Write("<br/>ApplicationInstance: " +  Context.ApplicationInstance.GetType().FullName);

It returns ApplicationInstance: ASP.global_asax, which should be returned according to a post.
Then why is the event not firing?

Please Help!!!

Thanks!!!

**[Edit] .... I added a line of code in Session_start event of Global.asax file and it worked. This means that Global.asax is getting deployed successfully. But why is Application_error event not getting executed in case of an error? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网白 2024-12-02 11:46:19

如果应用程序在 Application_error 方法中遇到,它不会抛出它,这使得该方法看起来像是没有被调用。

我会检查以确保 application_error 方法中有足够的异常处理。

If the application encounter within the Application_error method, it will not throw it which make it look like the method is not being invoke.

I would check to make sure you have adequate exception handling within the application_error method.

如梦初醒的夏天 2024-12-02 11:46:19

下面的代码在发布到 IIS 后工作正常。

Sub Application_Error(ByVal 发送者作为对象,ByVal e 作为 EventArgs)

    If Context IsNot Nothing Then
        Context.ClearError()
        Response.Write("Application_Error" + "<br/><br/>")
        Response.Write("Error on Default Page")
    End If
End Sub

Below code is working fine after publising to IIS.

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

    If Context IsNot Nothing Then
        Context.ClearError()
        Response.Write("Application_Error" + "<br/><br/>")
        Response.Write("Error on Default Page")
    End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文