I’m using Forms authentication and I would like to make use of roles, can I somehow set the role of the user without Membership ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A simple way to do it is to store the list of roles in the authentication ticket when the user is authenticated. Then for every request (
Application_AuthenticateRequestmethod of the global.asax file) you extract the roles, add them to aGenericPrincipalobject and set theHttpcontext.Userproperty.Your
User.IsInRole("role")and[AuthorizeAttribute(Roles="role")]will then work as normal.See this answer for code detailing how to do it.