mvc3中的自定义角色模块

mvc3中的自定义角色模块

本文介绍了mvc3中的自定义角色模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我是mvc3的新手. 我将要使用基于多个角色的系统.所以我已经为此user_master(user_id,user_name)创建了表3表,
role_master(角色ID,角色名称),
role_to_user(角色ID,用户ID),
我将创建自定义角色模块,并获得所有用户角色,但是现在我如何检查该角色.给我一个将多个角色分配给一个用户并按角色访问视图的示例示例.
例如,用户ID 1的角色ID为:1、5、7、9.
并会像这样检查状况

<%if(User.IsInRole(删除角色"))
{%>
< button id ="feedback-open-button" class ="buttonStyle1">新公司</button><%}%>
谢谢.

I am new in mvc3.
I will want to use multiple role based system. so i have create table 3 table for this user_master (user_id,user_name),
role_master(role_id,role-name),
role_to_user(role_id,user_id),
and i will create custom role module and i will get all user role but now how can i check this role. give me sample example for multiple role assign to one user and access view as per role.
for example user id 1 has role id:1,5,7,9.
and will check condition in view like this

<%if (User.IsInRole("delete role"))
{ %>
<button id="feedback-open-button" class="buttonStyle1" >New Company</button><% } %>
Thank you.

推荐答案

[Authorize(Roles="RoleNameHere")]
public ActionResult Foo()
{
   ....
}


请注意,Authorize也可以采用Users="Usernamehere",并且可以根据需要构建复杂的角色树.您的剃须刀if (User.IsInRole("delete role"))也可以使用.

如果需要快速尝试,请创建一个新的MVC3 Internet 应用程序.针对您的数据库运行ASPNET_regsql,并配置系统以使用该数据库.可以在此处找到详细说明 [ ^ ]


修复了一个拼写错误,该错误太过严重而无法忽略.现在,我需要检查字典中的"egregious"一词.


Note that the Authorize can also take Users="Usernamehere" and complex role trees can be built up if needed. Also your Razor if (User.IsInRole("delete role")) will work.

If you need to try this quickly, create an new MVC3 Internet application. Run ASPNET_regsql against your database and configure you system to use that database. Detailed instructions can be found here[^]


Fixed a spelling mistake that was too egregious to ignore. I now need to check the word egregious in the dictionary.


这篇关于mvc3中的自定义角色模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:22