我有一个ASP.NET应用程序, 在Global.asax应用程序错误事件中, 我调用一个方法来跟踪/记录错误。 我想在这里使用会话变量内容。 我使用了以下代码:
void Application_Error(object sender, EventArgs e)
{
//get reference to the source of the exception chain
Exception ex = Server.GetLastError().GetBaseException();
//log the details of the exception and page state to the
//Windows 2000 Event Log
GUI.MailClass objMail = new GUI.MailClass();
string strError = "MESSAGE: " + ex.Message + "<br><br><br>" + "SOURCE: " + ex.Source + "<br>FORM: " + Request.Form.ToString() + "<br>QUERYSTRING: " + Request.QueryString.ToString() + "<br>TARGETSITE: " + ex.TargetSite + "<br>STACKTRACE: " + ex.StackTrace;
if (System.Web.HttpContext.Current.Session["trCustomerEmail"] != null)
{
strError = "Customer Email : " + Session["trCustomerEmail"].ToString() +"<br />"+ strError;
}
//Call a method to send the error details as an Email
objMail.sendMail("test@gmail.com", "myid@gmail.com", "Error in " + Request.Form.ToString(), strError, 2);
}
我在访问会话变量的代码行中遇到了错误。Visual Studio提示:
此上下文中无法使用会话
我该如何解决这个问题?