global.asax Application_Error无法启动 [英] global.asax Application_Error not firing

查看:135
本文介绍了global.asax Application_Error无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的global.asax似乎没有触发.我有:

My global.asax seems not to be firing. I have:

void Application_Error(object sender, EventArgs e) 
{ 
    // Code that runs when an unhandled error occurs
    Server.Transfer("~/ExceptionFormView.aspx");
}

在我的web.config中,我没有CustomErrors之类的东西.因为我希望所有内容都由Global.asax处理并转移到ExceptionFormView.aspx.

In my web.config, I don't have anything like CustomErrors. As I want everything to be handled by Global.asax and transferred to ExceptionFormView.aspx.

它在本地运行良好,但是当我们部署到服务器时却无法运行.有什么想法吗?

It works fine locally, but not when we deploy to servers. Any thoughts?

我需要PrecompiledApp.config吗?

Do I need PrecompiledApp.config?

推荐答案

如果Web.config中没有customErrors部分,则与具有mode="RemoteOnly"的部分相同.此customError模式将使本地请求(从运行IIS的服务器发出)不使用自定义错误,它将按预期执行Application_Error()方法.远程请求将使用customErrors而不执行上述方法.

If you do not have a customErrors section in your Web.config, it is the same as having the section with mode="RemoteOnly". This customError mode will make local requests (made from the server running IIS) not use custom errors and it will execute the Application_Error() method as expected. Remote requests will use customErrors and not execute the method mentioned above.

这说明了为什么您在本地看到的行为与在服务器上看到的行为不同.通过将customErrors模式显式更改为On或Off,可以在任何环境下重现此行为.开启不会执行Application_Error()部分,而关闭会执行.

This explains why you are seeing different behavior locally than on your server. You can reproduce this behavior on any environment by changing the customErrors mode to On or Off explicitly. On will not execute the Application_Error() section while Off will.

<customErrors mode="On|Off|RemoteOnly" />

这当然不能解决您的问题,这是您无论如何都希望执行该方法.我在另一个问题上悬赏,我们试图找出这个问题为什么当customErrors模式为On时Application_Error()方法不触发.几天后再回到那里,看看我们是否找到了解决方案.

This doesn't solve your problem of course, which is you want the method to be executed regardless. I have a bounty on another question where we are trying to figure out why the Application_Error() method is not firing when customErrors mode is On. Check back there in a couple days to see if we have found a solution.

这篇关于global.asax Application_Error无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆