Last post Sep 23, 2011 01:13 AM by pchindhade
Sep 20, 2011 02:15 AM|pchindhade|LINK
I have application that uses sql server to store session data on the database.
Now i want to know that if user runs application that the session is created and stored in the database.
than how to know that user is logged in or logged out from application. ???
Sep 20, 2011 02:27 AM|reetvenky34|LINK
When User Logged into the system maintain varaible in seesion filed
when u want check the user is logged or not
if seesion["logged"] value is true user is loged in
other wise user is logged out and Session time is completed
Sep 20, 2011 02:36 AM|pchindhade|LINK
but ASPStateTempSessions does not maintain any column for this login logout process...??? my goal is to print session id of user logged in. than when user login from different browser than new entry will be made to database than how to know that same user
has come and inserted username and password and display all session id of same user logged in from diffrent locations ???
Sep 20, 2011 03:56 AM|Dave Sussman|LINK
The membership API can help with some of this. For example, the MembershipUser class has IsOnline, LastLoginDate and LastActivityDate properties which could be useful. You can use this like so:
MembershipUser usr = Membership.GetUser(); // gets the current user
MembershipUser usr = Membership.GetUser("Username"); // gets the name user
The only way to access session details would be to directly query the session table.
One problem you have though is that the session has a timeout, so closing a browser and opening another one would create a new session; eg I hit the close button by mistake, so I restart the browser but now I have a new session.
Sep 20, 2011 03:59 AM|pchindhade|LINK
yes thanks thats what i wanted...thanks for your reply....
Sep 20, 2011 07:23 AM|pchindhade|LINK
i have created the membership database and data are storing quite nicely. but now how can i map user with his session id in session tables.??
i searched membership tables but it does not store any data regarding session. so how can i know that user is logged in from particular how many session ids.
Sep 20, 2011 09:41 AM|Dave Sussman|LINK
If you're using in-process session state (the default) it doesn't store any session details in the database. If you use SqlServer mode it will create additional tables when you configure the session state. For that, see http://support.microsoft.com/kb/317604.
Sep 21, 2011 01:28 AM|pchindhade|LINK
i am using sql server mode. and i have configured it and session is storing but how to map session tables and membership tables
Sep 21, 2011 03:20 AM|Dave Sussman|LINK
Well, you can't really. You can only match the existing session because that's the only one you know about. You can query the session state table, but you don't have access to session IDs from other sessions and there's no map to the users. This is done
by default for security reasons.
The only option here would be to write an HttpModule that sits after the Session & Membership ones and does the mapping.
Sep 21, 2011 04:12 AM|pchindhade|LINK
so how can i do it with the help of http module...can you provide me some tutorial...??
Sep 21, 2011 10:22 AM|Dave Sussman|LINK
Actually, thinking about it, you can do it without a module. You could, for example, do something like:
1. In global.asax, get the session id and user ID and write them to a custom table. Do this in the Application_AuthenticateRequest event, which happens after the session has been created and the user authenticated.
- The table only needs two columns (UserID(uniqueidentifier) and SessionID (nvarchar(88)).
- When you write to the table, make sure there isn't already a matching entry; the AuthenticateRequest happens for every request, so you don't want to write the data everytime.
2. In global.asax, in the Session_End event, get the session ID and user ID and delete the entry from the custom table. This clears it up and keeps the table clean.
You now have a table that matches the session to the user.
Sep 23, 2011 01:13 AM|pchindhade|LINK
thanks, thanks a lot for this....