Forms Authentication how to get UserID

T

ThatsIT.net.au

I am using Forms Authentication but I want to keep more info on user than
forms authentication keeps.
I thought of 2 ways of doing this
1. To have a linked table holding other data, but for this I need to be able
to get the userID of the logged on user. how do I do this.
2. the other Idea I had was to add more fields to the forms authentication
user table. but I would still need the userID and I'm not sure what
implications this would have.

Any one know how to get the userID of the logged on user or a better way.

thanks
 
J

Joe Fawcett

ThatsIT.net.au said:
I am using Forms Authentication but I want to keep more info on user than
forms authentication keeps.
I thought of 2 ways of doing this
1. To have a linked table holding other data, but for this I need to be
able to get the userID of the logged on user. how do I do this.
2. the other Idea I had was to add more fields to the forms authentication
user table. but I would still need the userID and I'm not sure what
implications this would have.

Any one know how to get the userID of the logged on user or a better way.

thanks
The standard way would be to create your own Membership Provider and/or User
classes, then you can access any information via the User object.
 
S

Stan

I am using Forms Authentication but I want to keep more info on user than
forms authentication keeps.
I thought of 2 ways of doing this
1. To have a linked table holding other data, but for this I need to be able
to get the userID of the logged on user. how do I do this.
2. the other Idea I had was to add more fields to the forms authentication
user table. but I would still need the userID and I'm not sure what
implications this would have.

Any one know how to get the userID of the logged on user or a better way.

thanks

When the user logs in and is authenticated successfully store the
userID in a Session state variable e.g.

// Suppose you have the credentials stored in web.config
// (otherwise you would use an authentication function of your own
// that verifies against a database).

if(FormsAuthentication.Authenticate(txtUsername.text,
txtPassword.text))
{
Session["userID"] = txtUsername.Text;
FormsAuthentication.ReturnFromLoginUrl(...)
// etc
}

where txtUsername, txtPassword are a TextBoxes for entering the
username and password on the login form.

Then anytime later you can retrieve it thus:

string UserID = (string)Session["UserID"];


If, on the other hand, you are using Membership then the GetUser()
method will retrieve all details of the currently logged in user.
 

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

Top