I have my error handling setup to track all exceptions and write the information we need to a database and email out the developers who need to know about the error in order to fix it. The problem I run into is when the error occurs before the page has fully loaded. In this case the session variables I want to track are not available in Application_Error. So I do the following so that I don't get an error in my error handling, but there has to be a better way. Also if the page loads and the error occurs on submission of the form then the session variables are available.
try
{
user_name = System.Web.HttpContext.Current.Session["User_Name"].ToString();
user_number = System.Convert.ToInt32(System.Web.HttpContext.Current.Session["User_Number"].ToString());
}
catch (Exception ex)
{
user_number = 0;
user_name = "N/A";
}
Any help is greatly appreciated. Thanks!