Click here to Skip to main content
15,888,157 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

In Asp.net Application I have developed one web application In which i have used session Mode as sql server now As per asp.net rule when we use sql server mode , .net will not execute session_end event of glabal.asax file

so how to clear session in Sql Server mode ? I mean every time entry goes into ASPStateTempSessions table so when and how i can clear it when session goes time out , or user directly close browser or user click on log out button.

Web.Config Tag is

XML
<sessionState allowCustomSqlDatabase="true"  mode="SQLServer"  sqlConnectionString="Data Source=SERVER;Initial Catalog=TEMP;User ID=TEST;Password=TEST">
  </sessionState>


In Case here if i give time out to 8 to 9 hours then will it create any issue ? because in my application user will stay around 8 hours in site and most of the time user will be idle so...


Thanks In Advance.
Posted
Updated 13-Jun-20 3:52am
v2
Comments
Zoltán Zörgő 26-Mar-13 12:17pm    
See my comment to yours.

Hi,
Thanks for the reply,

I got most of my answer from this link
http://abhijitjana.net/2011/01/19/details-explanation-on-compression-enabled-session-for-sql-server-and-state-sever-session-mode-in-asp-net-4-0/#comment-11905

Event i have created one procedure which will delete logged in user detail when user click on log off button

But Could not find solution when user directly click on close (Click on X) button of browser - specially need a solution for Chrome Browser.(When user directly close browse then till session time out goes , data will persist in database so need a solution like when user close browser at the same time i will delete that particular user's data from database.)

Thanks
Shailesh vora
 
Share this answer
 
v2
Here are two important MSDN articles:
http://support.microsoft.com/kb/317604[^]
http://support.microsoft.com/kb/311209[^]
In the first one, there is the following paragraph:
Quote:
If entries in the ASPStateTempSessions table are not removed after the related sessions expire, make sure that the SQL Server agent is running. You can implement this functionality through stored procedures that are scheduled through jobs in SQL Server. The SQL Server agent manages these jobs.
As you see, the deletion is done by a job - thus won't work with SQL Express :(
By default, if you don't specify any initial catalog, the session data is stored in the tempdb (with all it's consequences). But you specified an other database (TEMP, that is not tempdb). Pay attention to the following paragraph in the second article:
Quote:
If you notice that the entries in the ASPStateTempSessions table are not removed after the related sessions have exceeded their expiration, make sure that SQL Server Agent is running. This functionality is implemented through stored procedures that are scheduled through jobs in SQL Server. SQL Server Agent manages these jobs.

You can of course implement other mechanism to handle session timeout, but all on sql server side. Make sure to have the session cookie and the authentication cookie timeout synchronized with the session timeout.
Theoretically, you might not encounter issues with long sessions, but keep in mind, that the database size might grow large. All depends on the number of users you are serving.
 
Share this answer
 
Comments
Zoltán Zörgő 26-Mar-13 12:07pm    
[comment from OP]
Thanks Zoltán , But is that any id (Session.SessionId) mapped with ASPStateTempSessions table ? if yes then i can write my own proc which can map session id with stored session id inside ASPStateTempSessions But i think it is storing some thing different, then how can we synchronize deletion when user click on logout button ?
Zoltán Zörgő 26-Mar-13 12:17pm    
1) Follow the instructions in the above msdn links, and check the table structure for yourself.
2) This mechanism is a predefined feature shipped with asp.net. You don't have to use it, but if you do, you have few things you can change
3) You can write your own provider, but it is not a simple task, see this for example.
4) If you align your mechanism in the common session handling of asp.net, you can use the common authentication and session methods (like Abandon), thus this "synchronization" is not an issue
Hi,

Can you share solution how did you delete session data from database after clicked on log off button.

Thanks
Gautav Gupta
Email: grvgupta305@gmail.com
 
Share this answer
 
Comments
CHill60 15-Jun-20 4:39am    
Please do not post questions or comments as solutions. Use the "Have a Question or Comment?" link next to the relevant post.
Also be aware that this is an open site - to post your email in open sites is to invite spam bots to flood your email. Don't share your email openly.

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