global.asax Application_Error 未触发
我的 global.asax 似乎没有被触发。我有:
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。
它在本地工作正常,但当我们部署到服务器时就不行了。有什么想法吗?
我需要 PrecompiledApp.config 吗?
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");
}
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?
Do I need PrecompiledApp.config?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您的 Web.config 中没有
customErrors
部分,则与具有mode="RemoteOnly"
部分相同。此 customError 模式将使本地请求(从运行 IIS 的服务器发出)不使用自定义错误,并且将按预期执行Application_Error()
方法。远程请求将使用customErrors并且不执行上面提到的方法。这解释了为什么您在本地看到的行为与在服务器上看到的行为不同。您可以通过将 customErrors 模式显式更改为“开”或“关”,在任何环境中重现此行为。 On 不会执行
Application_Error()
部分,而 Off 则会执行。当然,这并不能解决您的问题,即您无论如何都希望执行该方法。我对另一个问题有赏金,我们正在尝试解决这个问题为什么当 customErrors 模式打开时
Application_Error()
方法没有触发。几天后回来看看我们是否找到了解决方案。If you do not have a
customErrors
section in your Web.config, it is the same as having the section withmode="RemoteOnly"
. This customError mode will make local requests (made from the server running IIS) not use custom errors and it will execute theApplication_Error()
method as expected. Remote requests will use customErrors and not execute the method mentioned above.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.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.如果您使用的是 IIS 7,请尝试设置:
If you are using IIS 7, try setting:
如果您之前将应用程序部署为预编译,但现在不是,那么您需要删除 bin 目录中的 PrecompiledApp.config 和 Deployment.dll。 .NET 将使用 Deployment.dll 中的全局代码而不是您的更改。
If you previously deployed your application as precompiled but now you are not, then yes, you need to delete PrecompiledApp.config and your Deployment.dll in the bin directory. .NET will use the global code in Deployment.dll instead of your changes.
在IIS7中,集成了应用程序池。它必须是经典的:
http://praveenbattula.blogspot.com/ 2009/12/iis-7-托管管道模式-globalasax.html
In IIS7, the application pool is integrated. It needs to be classic:
http://praveenbattula.blogspot.com/2009/12/iis-7-managed-pipeline-mode-globalasax.html