On 17 May, 05:28, "ThatsIT.net.au " <me@workwrote :
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(FormsAuthent ication.Authent icate(txtUserna me.text,
txtPassword.tex t))
{
Session["userID"] = txtUsername.Tex t;
FormsAuthentica tion.ReturnFrom LoginUrl(...)
// 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.