发布后未触发 application_error 事件
我知道这个问题已经被问过很多次了,但我无法从这些帖子中得到解决。
我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果应用程序在 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.
下面的代码在发布到 IIS 后工作正常。
Sub Application_Error(ByVal 发送者作为对象,ByVal e 作为 EventArgs)
Below code is working fine after publising to IIS.
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)