use*_*150 1 asp.net-mvc asp.net-mvc-3 asp.net-mvc-4
我在项目中创建了一个控制器.
[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);
}
Run Code Online (Sandbox Code Playgroud)
我想检查控制器内部的权限,而不是外部.
例如,像这样的事情:
public ActionResult Index()
{
if(Role=admin) return view2
if(role=teacher) return view1
}
Run Code Online (Sandbox Code Playgroud)
我可以这样做吗?!!
最好的祝福
你应该可以使用 User.IsInRole()
public ActionResult Index()
{
if(User.IsInRole("admin"))
{
//Return View
}
else if(User.IsInRole("teacher"))
{
//Return View
}
else
{
//Return View
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3777 次 |
| 最近记录: |