473,473 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Warning in Session_End()

11 New Member
After the session end i try to write the session value.In this, it write the session value after the session end, but i got the warning in application event.

My asp code:
Expand|Select|Wrap|Line Numbers
  1. void Session_End(object sender, EventArgs e)
  2.     {
  3.         // Code that runs when a session ends. 
  4.  
  5.         // Note: The Session_End event is raised only when the sessionstate mode
  6.         // is set to InProc in the Web.config file. If session mode is set to StateServer
  7.         // or SQLServer, the event is not raised.        
  8.  
  9.         string domainName = AppDomain.CurrentDomain.BaseDirectory.ToString();
  10.         string strDirName = domainName.Replace("bin\\Debug\\", "");
  11.  
  12.         string enableLogging = ConfigurationSettings.AppSettings.Get("EnableSessionLog");
  13.  
  14.         if (enableLogging.ToLower() == "true")
  15.         {
  16.  
  17.             TextWriter tw = new StreamWriter(strDirName + "Log Files\\SessionLog.txt", true);
  18.             if (Session["portalID"] != null)
  19.             {
  20.                 tw.WriteLine("Session Ends");
  21.                 tw.WriteLine(DateTime.Now + "  SessionTimedout SessionID = " + Session.SessionID);
  22.                 tw.WriteLine(DateTime.Now + "  SessionTimedout UserName = " + Session["session_username"].ToString());
  23.                 tw.WriteLine(DateTime.Now + "  SessionTimedout PortalID = " + Session["portalID"].ToString());
  24.                 tw.WriteLine(DateTime.Now + "  SessionTimedout PatientID = " + Session["patientID"].ToString());
  25.             }
  26.             tw.Close();
  27.  
  28.         }
  29.     }    
My Warning is:

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
Sep 1 '09 #1
1 3032
Frinavale
9,735 Recognized Expert Moderator Expert
@anithaapr05
Always check to see if the values in session are null before trying to use them. It seems that you are attempting to access Objects that no longer exist. First check if they exist, and if they do exist then use them. Don't ever assume that they exist...

It should look something like:
Expand|Select|Wrap|Line Numbers
  1.    if (enableLogging.ToLower() == "true")
  2.    {
  3.  
  4.             TextWriter tw = new StreamWriter(strDirName + "Log Files\\SessionLog.txt", true);
  5.             if (Session["portalID"] != null)
  6.             {
  7.                 tw.WriteLine("Session Ends");
  8.                 if(Session != null){
  9.                   If(Session.SessionID != null){
  10.                     tw.WriteLine(DateTime.Now + "  SessionTimedout SessionID = " + Session.SessionID);
  11.                   }
  12.                  }
  13.                 If(Session["session_username] != null){
  14.                   tw.WriteLine(DateTime.Now + "  SessionTimedout UserName = " + Session["session_username"].ToString());
  15.                 }
  16.                 if(Session["portalID"] != null){
  17.                   tw.WriteLine(DateTime.Now + "  SessionTimedout PortalID = " + Session["portalID"].ToString());
  18.                 }
  19.                 if(Session["patientID"] != null){
  20.                   tw.WriteLine(DateTime.Now + "  SessionTimedout PatientID = " + Session["patientID"].ToString());
  21.                 }
  22.             }
  23.             tw.Close();
  24.     }
  25.  
Sep 1 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris Sibel | last post by:
Hey guys I have a user tracking setup to track users. What it does is once a user hits my site it sends me an email telling me some info and once a user clicks the logout button it sends a second...
9
by: Kenn Ghannon | last post by:
I've got an ASP.NET page with a counter subtraction routine in the Session_End method in the Global.asax.cs: protected void Session_End(Object sender, EventArgs e) { ulong curUsers; ...
2
by: Bela | last post by:
Hello I was wondering if someone could help me out with a Session_End problem in my Global.asax. I've tried everything, and still no success Here is the scenario: sessionstate is set to InProc....
3
by: Guadala Harry | last post by:
Just wondering if Session_End *always fires* for every Session. I know that IIS times out sessions after a default 20 min (unless changed) and there's no way to know when a user actually closed a...
7
by: Henry | last post by:
I have a question on session_end. I'm trying to log into my database when the session times out, it will store user info into a table. When I got step into a line where I was trying to open...
8
by: Roger | last post by:
When I call the session.abandon() method, it calls the session_end event. When a user closes the browser or clicks the log off button, I can dispose of objects and abandon the session cleaning....
1
by: =?Utf-8?B?YnJlbnQ5NjA=?= | last post by:
Environment: ASP.NET 2.0, SQL Server 2005, C#, Visual Studio 2005 In my Session_End event, I am executing a stored procedure to update a database table that is used to log user sessions. When...
12
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I am trying to maintain a list of people who are currently "online" in SQL. I do this by adding a simple entry to a simple PeopleOnline table whenever someone logs in to my site. If they...
1
by: anithaapr05 | last post by:
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.But i got the waring in event...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.