在asp.net MVC应用程序角色管理(如何)? [英] application role management in asp.net mvc (How)?

查看:98
本文介绍了在asp.net MVC应用程序角色管理(如何)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了asp.net的MVC + C#应用程序。它有2个用户为超级管理员,管理员和用户。我要管理的功能,按照自己的角色。我在管理SQL Server数据库中的数据。如何在asp.net mvc的管理呢?在那里我shuold必须写code这个管理?

I have developed the asp.net mvc + C# application. it has 2 users as Super admin, Admin and User. I want to manage the functionality as per their roles. I am managing the data in sql server database .How to manage this in asp.net mvc ? where shuold i have to write the code for this management ?

推荐答案

好吧,我能想到的两种选择。

Well, I can think of two options.

您可以使用asp.Net默认的的SqlMembershipProvider sqlRoleProvider 验证和授权用户。如果你这样做,你必须与你结合其数据库。在这种情况下,您只需编写:

You can use asp.Net's default sqlMembershipProvider and sqlRoleProvider to authenticate and authorize your users. If you do so you have to incorporate its database with yours. In this case you only have to write:

[Authorize(Role="Administrator")]
public ActionResult myAction(){}

批准属性将只允许管理员输入 myAction 的ActionResult。 (检查是否有在asp.net成员和角色数据库管理员角色 - 大概有五六个角色有,但我还没有使用过)。

The authorize attribute will only allow administrators to enter myAction actionresult. (Check to see if there is administrator role in asp.net membership and role database - there are almost half dozen roles there but I have not used them).

第二个选择是使用自己的数据库,用于存储角色信息,并编写自己的授权属性,并与他们装饰你的 actionresults
这个问题将帮助您了解如何从 AuthorizeAttribute 继承来写你的自定义授权逻辑。

The second option is to use your own database for storing role information and writing your own authorize attributes and decorating your actionresults with them. this question will help you understand how you can inherit from AuthorizeAttribute to write your custom authorization logic.

这篇关于在asp.net MVC应用程序角色管理(如何)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆