Err_ application not working?

In Webform1.aspx.cs:

protected void Page_Load(object sender, EventArgs e) { throw new Exception("test exception"); } 

In the Global.asax.cs file:

 protected void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs if (Server.GetLastError() is HttpUnhandledException) Server.Transfer("ErrUnknown.aspx"); } 

But the Application_Error event handler is never called. Instead, I get a runtime error page.

What do I need to do if the called Err application is called after the exception is thrown?

+6
source share
2 answers

It looks great and is raised by Application_Error.

Have you checked Debugging your application?

Actually, you are missing Server.ClearError() , so the exception is thrown by asp.net, but you have to suppress it because you are handling it yourself.

 protected void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs if (Server.GetLastError() is HttpUnhandledException) { // suppressing the error so it should not pass to asp.net Server.ClearError(); Server.Transfer("ErrUnknown.aspx"); } } 
+5
source

I found a problem.

 Server.Transfer("ErrUnknown.aspx") 

was the reason.

When I tried to view "ErrUnknown.aspx" directly in the browser, I realized that there was an error on this page. After fix Server.Transfer works

Was it misleading, although this event does not fire when debugging the application?

Anyway.

+1
source

Source: https://habr.com/ru/post/885554/


All Articles