Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

asp.net - global.asax Application_Error not firing

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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" />

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...