开发者

Call up last exception on an ASP.NET error page

开发者 https://www.devze.com 2022-12-30 10:56 出处:网络
I\'ve got an error page here SiteError.aspx and it\'s configured correctly in the web.config to go there when unhandled exceptions are encountered.

I've got an error page here SiteError.aspx and it's configured correctly in the web.config to go there when unhandled exceptions are encountered.

I want to use this page to log the exception that triggered it as well because I only want to LOG the errors that the users encounter (i.e. if SiteError.aspx is ever hit.)

This is the code I Have:

In the 开发者_如何学PythonOnLoad(...) in SiteError.aspx

    Exception lastEx = Context.Server.GetLastError();
    if (lastEx != null)
        log.Error("A site error was encountered", lastEx);

However, my log is never showing up in my Output, and If i breakpoint on line 2 (in this example) code execution is never interupted (after letting the exception clear to ASP.NET handling in the debugger.


This might help you. http://support.microsoft.com/kb/306355

See section "How to use the Web.config file"

I think you'll need to add a Global.asax to your project and handle the error in the Application_Error method.

0

精彩评论

暂无评论...
验证码 换一张
取 消