Tôi có một ứng dụng ASP.NET và trong Global.asax 'Application Error Event, tôi gọi một phương thức để theo dõi/đăng nhập lỗi. Tôi muốn sử dụng phiên làm việc nội dung biến ở đây .Tôi sử dụng mã dưới đâyASP.NET: Truy cập phiên biến trong 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("[email protected]", "[email protected]", "Error in " + Request.Form.ToString(), strError, 2);
}
tôi nhận được một lỗi trong dòng mã nơi tôi truy cập vào phiên variable.Visual Studio được nói rằng
"phiên không có sẵn trong ngữ cảnh này "
Làm cách nào để loại bỏ điều này? Có suy nghĩ gì không?
Cảm ơn trước
Lỗi được đưa ra từ đâu? Trong mã aspind beind (sự kiện nào?), Hoặc trong trình xử lý http, v.v ...? Điều này có thể xác định xem việc sử dụng đối tượng phiên có hợp lệ hay không – JonoW