-
September 14th, 2011, 03:55 AM
#1
Session expired after browser closed
Hi all,
I'm having a problem with the session after the browser is closed. When the browser is (completely) closed, I always need to login in again on my own website. I don't need to login if only one tab is closed.
So for example:
Situation 1:
- Open a browsers
- Open a second tab, open my site (and login).
- Close second tab and reopen my site (no login needed)
Situation 2:
- Open a browser.
- Open a second tab, open my site (and login).
- Close all tabs and browser completely. When I now open my site again, I have to login.
I'm use State Server to maintain the session state. I tested the same with 'In Process', but has the same result.
Any idea what is causing this and how to solve? When I google for this, I can only find people who are trying to expire the session on browser close. That's completely the other way around. Am I missing something?
Thanks,
Danny
-
September 14th, 2011, 04:42 AM
#2
Re: Session expired after browser closed
It depends on where your site is storing the login info..
If it's using a per-session cookie .. the session info is lost when the browser is closed (per-session cookies are kept in memory and not disk)
if it's using persistent cookies, then the info is stored to disk, and available on startup of the browser..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
September 14th, 2011, 04:48 AM
#3
Re: Session expired after browser closed
I'm using the defaults of ASP.NET. I guess this is per-session cookie..
Is there any kind of setting to use persistent cookies? Or do I need to write the session id into the correct cookie each request?
-
September 14th, 2011, 04:52 AM
#4
Re: Session expired after browser closed
have a look at this MSDN entry
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
September 14th, 2011, 05:00 AM
#5
Re: Session expired after browser closed
I don't understand a few things:
The SessionID property is used to uniquely identify a browser with session data on the server. The SessionID value is randomly generated by ASP.NET and stored in a non-expiring session cookie in the browser
Non-expiring? It does expire right?!
When using cookie-based session state, ASP.NET does not allocate storage for session data until the Session object is used. As a result, a new session ID is generated for each page request until the session object is accessed.
I use the session object on every page request, and still I receive a new session id on each request.
-
September 14th, 2011, 05:39 AM
#6
Re: Session expired after browser closed
Originally Posted by dannystommen
Non-expiring? It does expire right?!
Right and Wrong ... It does not expire for as long as the browser stays open, It the browser app stays open and runs for 10 years, the Session cookie would not have expired.
Originally Posted by dannystommen
I use the session object on every page request, and still I receive a new session id on each request.
Are you calling the original Session Object or creating a new one????
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
September 14th, 2011, 05:41 AM
#7
Re: Session expired after browser closed
Originally Posted by GremlinSA
Are you calling the original Session Object or creating a new one????
Don't know actually.. I'm simply using Session["user"] = ...
-
September 15th, 2011, 06:53 AM
#8
Re: Session expired after browser closed
Originally Posted by dannystommen
Don't know actually.. I'm simply using Session["user"] = ...
I suggest you check....
And the 'Code Snip' you gave helps nothing to help determine if you are or aren't .....
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
September 15th, 2011, 07:43 AM
#9
Re: Session expired after browser closed
I didn't know that there's a difference between using the original Session object or creating a new one. That's why I said "don't know actually", so I have also no idea how to check this either.
As mentioned before, in the OnInit event of each page request I do the following
Code:
if (Session["user"] == null)
{
Response.Redirect("/login.aspx");
}
In the login page:
Code:
..
Session["user"] = loggedInUser;
I guess that I'm using the original Session object, right?
-
October 3rd, 2011, 12:31 AM
#10
Re: Session expired after browser closed
Originally Posted by dannystommen
I didn't know that there's a difference between using the original Session object or creating a new one. That's why I said "don't know actually", so I have also no idea how to check this either.
As mentioned before, in the OnInit event of each page request I do the following
Code:
if (Session["user"] == null)
{
Response.Redirect("/login.aspx");
}
In the login page:
Code:
..
Session["user"] = loggedInUser;
I guess that I'm using the original Session object, right?
http://csharpdotnetfreak.blogspot.co...-redirect.html
This may be helpful. Let me know.
Regards,
Quinn
-
October 3rd, 2011, 02:31 AM
#11
Re: Session expired after browser closed
Quinn, I don't see want your article tries to explain.
I've created a workaround I found somewhere, and seems to work just fine
Code:
protected override void OnPreInit(EventArgs e) {
base.OnPreInit(e);
//make session cookie 'persistant', otherwise it will expire on browser close
if (Session != null) {
//create cookie with session id name
HttpCookie cookie = new HttpCookie("ASP.NET_SessionId");
//add the session id
cookie.Value = Session.SessionID;
//set expire to 12 hours
cookie.Expires = DateTime.Now.AddHours(12);
//add the cookie to the response
Response.Cookies.Add(cookie);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|