473,763 Members | 5,610 Online
Bytes | Software Development & Data Engineering Community
+ 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: 7d1169968dd9490 2bc75c75234933e 12
Event sequence: 968
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: b42109ff-1-128952191043738 926
Trust level: Full
Application Virtual Path: /ApplicationName
Application Path: C:\ApplicationN ame\
Machine name: MachineName

Process information:
Process ID: 3576
Process name: WebDev.WebServe r.EXE
Account name: MachineName\Adm inistrator

Exception information:
Exception type: NullReferenceEx ception
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\Adm inistrator

Thread information:
Thread ID: 10
Thread account name: MachineName\Adm inistrator
Is impersonating: False
Stack trace: at ASP.global_asax .Session_End(Ob ject sender, EventArgs e) in c:\ApplicationN ame\Global.asax :line 80

I got the warning in this line- tw.WriteLine(Da teTime.Now + " SessionTimedout UserName = " + Session["session_userna me"].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 3044
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
11390
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 email that tells me what pages the visited, how long they were on each page, etc. The second email is in the Session_End Sub and the first is in the Session_Start. Now my question is Why is it that the Session_End is never fired. I was forced to...
9
10802
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; Application.Lock();
2
4732
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. I have timeout set to 1 min I have a variable in session_start that is incremented each new session, and it is then decremented in Session_End. I use this variable on a web form to show current users online. All of this works just fine, so I...
3
566
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 browser (unless I provide a "log out" button that kills the session explicitly, and we can't guarantee the user will click on that). What I am wondering if there are there well-known/documented circumstances under which Session_End will NOT fire...
7
1643
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 connection (I had it set to timeout in 1 minute, and ran it in debug mode), nothing happens. I read somewhere before about how database call can't work with these settings in my web.config file. I'm using <authentication mode="Windows" /> and <identity...
8
5769
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. But, when a user either navigates away from the web app and when the session timesout, the session_end event does not seem to fire. Or when else can I dispose of objects? Or is there an event I can you that is fired when a user navigates away from...
1
6937
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 the user sessions time out, the Session_End event fires successfully. The stored procedure executes successfully, and I can see the updated data in the database just as I would expect. Nonetheless, an exception is being generated by the code...
12
10698
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 manually log OUT of the site, I have no problem deleting them from the PeopleOnline table. But if they just close the browser, I was assuming I'd have to use the Session_End() event in Global.asax even though I know that this will only occur once the...
1
2846
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 viewer. My Waring is Event code: 3005 Event message: An unhandled exception has occurred. Event time: 8/14/2009 3:04:16 PM
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.