Syntax
Syntax

Reputation: 27

User Define Role and Right on Membership Provider on MVC

Dear All, I am using the membership provider of MVC framework, Now i want to implement the Role and Right on My project, All the Role and Right is available on database so how can i implement the Role and Right? is there is any built in function which can i use? also i am using the Ado .net Data Entity Framework..

Upvotes: 0

Views: 585

Answers (2)

W.Jackson
W.Jackson

Reputation: 407

If I'm understanding what you want to do correctly, you have to annotate your Controller class or ActionResult with the Authorize attribute like this:

[Authorize(Roles="Domain Admins", Users="testuser")]
public class TestController : Controller {

}

Then as long as your membership provider is setup you should be good to go.

It may be worth mentioning that you can always check if a user is in a role with the following code.

User.IsInRole("Domain Admins");

If your using MVC2 then the default project template makes it easy. You should check out the AccountController and AccountModels in a default MVC2 template.

Upvotes: 1

Related Questions