FormsAuthentication and Session

J

Joe

I'm using FormsAuthentication and need to track a user id (int) along with
the user name. I was trying to store the user id under the Session but if
the user closes the browser and opens another browser and goes back to the
page the user is still logged in.

I have 2 choices:
1 - Log the user out whenever the browser is closed
2 - Store the user id in a cookie.

I would prefer option 1 but I don't know how to Sign out the user when the
browser is closed and the session is no longer valid.
 
L

Lucas Tam

I'm using FormsAuthentication and need to track a user id (int) along
with the user name. I was trying to store the user id under the
Session but if the user closes the browser and opens another browser
and goes back to the page the user is still logged in.

I have 2 choices:
1 - Log the user out whenever the browser is closed
2 - Store the user id in a cookie.

I would prefer option 1 but I don't know how to Sign out the user when
the browser is closed and the session is no longer valid.

You can extend the IPrincipal and IIdentity
(FormsIdentitiy/GenericIdentity) interfaces to add custom data to your
user clasess.

This page sort of explains the process and does a bit more too:

http://www.codeproject.com/aspnet/rolesbasedauthentication.asp
 
P

Patrick.O.Ige

Why don't you use FormsAuthSignOut()
And then use Session.Abandon..
Hope that helps..
or PS do it in the Global.asax
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top