【发布时间】:2012-04-26 17:51:36
【问题描述】:
我没有很多这方面的经验,我真的希望从你们那里得到一个好的建议。我需要实现以下安全方案,我想知道最好的方法。
假设我们有员工、主管和部门经理。 员工和主管都根据他们所属的部门经理分配了 ManagerId。
当主管用户登录时,我希望他只看到与他的 ManagerId 属于同一 ManagerId 的员工的记录。 如果另一个主管使用另一个 ManagerId 用户登录并在 url 中手动打卡其他员工的信息(例如: wwww.domain.com/employee/details/{id} ), 因为他的 ManagerId != 员工的 ManagerId 我希望限制访问。
有意义吗?
我开始在所有 ActionMethod 上输入检查,例如:
public ActionResult Details(int id)
{
var employee = employeeRepository.Get(id)
var user = (CustomIdentity)ControllerContext.HttpContext.User.Identity;
if(employee.managerId == user.managerId)
{
Do whatever...
}
else
{
Not allowed
}
}
但是在所有 ActionMethods 中输入它似乎是多余的,只是......嗯......我知道一定有更好的方法。
【问题讨论】:
标签: c# asp.net-mvc security authentication