Asp.net 4.0: How to get information about exceptional details on a custom error page?

We are using the custom error provided by the asp.net configuration setting. Throughout the application (PL / BLL / DAL) we do not use any attempts. Therefore, for any exception in the application at any level, it redirects the user to the user error page specified in the user settings for the error in the configuration file. Now we want to write the following information to the log file before showing the error page:

- Date & time - Exception message & strack trace. - Page Name - Method Name - Method Parameter & values. 

Please help me how to collect the above information in a custom error_page_load message

Thanks,

@Paul

+6
source share
2 answers

You can store error data in the session and receive it on the user error page.

This code is in Global.asax :

  protected void Application_Error(object sender, EventArgs e) { Exception err = Server.GetLastError(); Session.Add("LastError", err); } void Session_Start(object sender, EventArgs e) { Session["LastError"] = ""; //initialize the session } 

Then on the error page page :

  protected void Page_Load(object sender, EventArgs e) { Exception err = Session["LastError"] as Exception; //Exception err = Server.GetLastError(); if (err != null) { err = err.GetBaseException(); lblErrorMsg.Text = err.Message; lblSource.Text = err.Source; lblInnerEx.Text = (err.InnerException != null) ? err.InnerException.ToString() : ""; lblStackTrace.Text = err.StackTrace; Session["LastError"] = null; } } 
+11
source

Set this attribute in the customErrors section of web.config: redirectMode = "ResponseRewrite"

0
source

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


All Articles