Forms Authentication UserData

  • Thread starter Thread starter Brian Shannon
  • Start date Start date
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
 
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

Back
Top