【发布时间】:2021-05-17 17:39:38
【问题描述】:
如何为 ASP.NET MVC 5 中的操作创建 CustomAuthenticationAttribute 依赖参数,我的意思是如果我发送到模块 5,这意味着获取数据相关的老师,如果我发送 3 作为模块中的参数,返回学生.我想添加两个权限(学生和教师)以允许用户访问学生或教师或两者。
[CustomAuthentication(PermissionCode = "Student_View")]
public ActionResult Index(int module)
{
}
我有问题是因为CustomAuthentication相关页面代码(我将添加两段代码)student_View和teacher_View
【问题讨论】:
-
属性是在编译时应用的,因此它们不能根据参数表现不同
-
那么,有什么解决方案可以解决这个问题,检查权限依赖参数,可以在 Action 中添加验证吗?
标签: c# asp.net-mvc permissions roles custom-authentication