用户在 MVC 上定义会员提供者的角色和权限

发布于 2024-10-07 02:46:51 字数 115 浏览 0 评论 0原文

各位, 我正在使用MVC框架的成员资格提供程序,现在我想在我的项目上实现角色和权限,所有角色和权限都在数据库中可用,那么我如何实现角色和权限?有没有我可以使用的内置函数?我也在使用 Ado .net 数据实体框架..

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感受沵的脚步 2024-10-14 02:46:51

如果我理解您想要正确执行的操作,则必须使用 Authorize 属性注释您的 Controller 类或 ActionResult,如下所示:

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

}

然后,只要设置了您的会员资格提供程序,您就可以开始了。

可能值得一提的是,您始终可以使用以下代码检查用户是否具有角色。

User.IsInRole("Domain Admins");

如果您使用 MVC2,那么默认的项目模板会让这一切变得简单。您应该检查默认 MVC2 模板中的 AccountController 和 AccountModels。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文