My asp code:
Expand|Select|Wrap|Line Numbers
- void Session_End(object sender, EventArgs e)
- {
- // Code that runs when a session ends.
- // Note: The Session_End event is raised only when the sessionstate mode
- // is set to InProc in the Web.config file. If session mode is set to StateServer
- // or SQLServer, the event is not raised.
- string domainName = AppDomain.CurrentDomain.BaseDirectory.ToString();
- string strDirName = domainName.Replace("bin\\Debug\\", "");
- string enableLogging = ConfigurationSettings.AppSettings.Get("EnableSessionLog");
- if (enableLogging.ToLower() == "true")
- {
- TextWriter tw = new StreamWriter(strDirName + "Log Files\\SessionLog.txt", true);
- if (Session["portalID"] != null)
- {
- tw.WriteLine("Session Ends");
- tw.WriteLine(DateTime.Now + " SessionTimedout SessionID = " + Session.SessionID);
- tw.WriteLine(DateTime.Now + " SessionTimedout UserName = " + Session["session_username"].ToString());
- tw.WriteLine(DateTime.Now + " SessionTimedout PortalID = " + Session["portalID"].ToString());
- tw.WriteLine(DateTime.Now + " SessionTimedout PatientID = " + Session["patientID"].ToString());
- }
- tw.Close();
- }
- }
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 8/20/2009 11:19:24 AM
Event time (UTC): 8/20/2009 5:49:24 AM
Event ID: 7d1169968dd94902bc75c75234933e12
Event sequence: 968
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: b42109ff-1-128952191043738926
Trust level: Full
Application Virtual Path: /ApplicationName
Application Path: C:\ApplicationName\
Machine name: MachineName
Process information:
Process ID: 3576
Process name: WebDev.WebServer.EXE
Account name: MachineName\Administrator
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Request information:
Request URL:
Request path:
User host address:
User:
Is authenticated: False
Authentication Type:
Thread account name: MachineName\Administrator
Thread information:
Thread ID: 10
Thread account name: MachineName\Administrator
Is impersonating: False
Stack trace: at ASP.global_asax.Session_End(Object sender, EventArgs e) in c:\ApplicationName\Global.asax:line 80
I got the warning in this line- tw.WriteLine(DateTime.Now + " SessionTimedout UserName = " + Session["session_username"].ToString());
After session end i tried to write the session value.Please any one tell me how to avoid this