0

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..

Syntax
  • 27
  • 3

2 Answers2

1

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.

W.Jackson
  • 397
  • 1
  • 11