I have created an MVC4 Web App with Windows Auth. Is it possible to define which users have access to what using something like: [Authorize(Roles=”Admin”)] without relying on AD i.e. specified within database table or within App itself?
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.
Absolutely. You need to create a custom role provider that checks role memberships based on whatever you have on the back end.
The custom role provider derives from
System.Web.Security.RoleProvider, and you need to override at least theGetRolesForUserandIsUserInRolemethods.The
GetRolesForUsermethod is the one used by theAuthorizeattribute. After the user is authenticated the attribute calls this method with the user’s SamAccountName and expects the method to return astring[]containing the names of the roles the user is a member of.See http://msdn.microsoft.com/en-us/library/8fw7xh74(v=vs.100).aspx for more details