Store/assign roles of authenticated users
asp.net, asp.net-mvc, authentication, forms-authentication
Solution
When you authenticate your user, you generate a new GenericPrincipal instance. The constructor takes an array of strings which are the roles for the user. Now set HttpContext.Current.User equal to the generic principal and write the auth cookie, and that should do it.
Problem
I am upgrading a site to use MVC and I am looking for the best way to set up Authentication. At this point, I have the log-in working off of Active Directory: validating a username and password, and then setting the Auth cookie. How do I store the user's role information at time of log-in, in order for my controllers to see those roles as the user navigates through the site? ``` [Authorize(Roles = "admin")] ``` I have no problem getting a list of roles from Active Directory. I just don't know where to put them so that the controllers will see them.