【发布时间】:2014-04-24 11:25:03
【问题描述】:
我在我的项目中创建了一个控制器。
[Authorize(Roles = "Admin")]
private StudentRepositor obj = new StudentRepositor();
public ActionResult Index()
{
var model = obj.GetStudentlist();
foreach (var stu in model)
{
stu.State = (stu.State == "1") ? "فعال" : "غیرفعال ";
}
return View(model);
}
我想检查控制器内部而不是外部的权限。
例如这样的事情:
public ActionResult Index()
{
if(Role=admin) return view2
if(role=teacher) return view1
}
我可以这样做吗?!!
最好的问候
【问题讨论】:
-
您需要使用自定义授权属性:stackoverflow.com/questions/21958304/…
-
您可以根据角色返回视图或操作
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4