I have got the warning in event viewer when i wrote the code in global.asax session_end().
When the user sessions time out, the Session_End event fires successfully.Bu t i got the waring in event viewer.
My Waring is
My session_end() code is
Please tell me how to avoid this problem
When the user sessions time out, the Session_End event fires successfully.Bu t i got the waring in event viewer.
My Waring is
Code:
Event code: 3005 Event message: An unhandled exception has occurred. Event time: 8/14/2009 3:04:16 PM Event time (UTC): 8/14/2009 9:34:16 AM Event ID: 981e4e58a2cd43f293827e9350c15da9 Event sequence: 731 Event occurrence: 2 Event detail code: 0 Application information: Application domain: 6a76b598-9-128947141739218750 Trust level: Full Application Virtual Path: /Sample Application Path: C:\Sample\ Machine name: MachineName Process information: Process ID: 3928 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: 4 Thread account name: MachineName\Administrator Is impersonating: False Stack trace: at ASP.global_asax.Session_End(Object sender, EventArgs e) in c:\Sample\Global.asax:line 80
My session_end() code is
Code:
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(); } }
Comment