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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top