Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to maintain a session through out a browser until it closes with out any login form
Posted
Comments
Tom Marvolo Riddle 5-Apr-14 2:20am    
What do you want to maintain?
Er. Puneet Goel 5-Apr-14 2:32am    
Like what kinda of sessions you want to set up?
Member 10378142 5-Apr-14 2:43am    
i want to maintain a unique number for each time when a browser opens
Er. Puneet Goel 5-Apr-14 5:50am    
ok, will it be for single web application or cross web application?
Member 10378142 7-Apr-14 4:48am    
cross web application

Try with GUID Concept

Guid obj= new Guid();
session["unqno"]=obj.ToString();


Use this in HomePage load
 
Share this answer
 
v2
In my view if you just want to avoid authentication on session timeout you can opt for maintaining SessionID in Application Context once successfully authenticated.

STEP 1:
After successful authentication keep the current SessionID and UserId in the Application State.
Also keep the UserID in the current session.

STEP 2:
On page load
If UserID exists in current session then go ahead.
Else check if the Request SessionID(you could determine from HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value) exists in your Application State.
{
If exists then store the UserID in current session and go ahead.
Else user hits first time, so redirect to logon page.
}

STEP 3:
Expire the user session on following events;
1. Logout by user
2. Catch the browser close event from JavaScript and notify the server to close the session.

Other points to note:
1. You must understand that, you should not use the session variable in this scenario.
2. Use following configuration to avoid generate same SessionId again, and avoid conflicting with other user session.
<configuration>
<system.web>
regenerateExpiredSessionId="false" />


3. Still there could be some live SessionID in your Application state, which actually does not exists as browser crashed or something unusual happened. So need to clean those periodically.
 
Share this answer
 
Comments
anup.bhunia 14-Apr-14 14:03pm    
did it solve your problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900