Forms Authentication UserData

B

Brian Shannon

Using forms authentication I want to add several pieces of data to the
UserData property in the Forms Ticket.

I want to include roles, email, user ID.

From reading it seems like you add all that to a string and add it to the
UserData property.

If that is the case how do you access each individual piece such as email.
I am not completely up to date with using ASP.NET's cookies so bare with me.

Thanks
 
K

Karl

Brian,
What I've done in the past is simply store the ID and look up the user from
that (users should be cached, so no perf issue)

int userId = Convert.ToInt32(context.User.Identity.Name);
MyUserClass user = MyUserClass.GetUser(userId);
string email = user.Email;


the GetUser function looks something like:
public static User GetUser(int userId){
User user = (User)HttpRuntime.Cache[userId.ToString()]
if (user == null){
//get from DB and store in cache for next time.
}
return user;
}

Karl
 

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,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top