使用Windows身份验证的MVC3 Web应用程序中的权限提升

Pro*_*ofK 10 asp.net-mvc asp.net-authorization asp.net-mvc-3

我需要在MVC3 Web应用程序中实现用户权限提升,对于Forms和Windows身份验证,但这个问题对于Windows身份验证至关重要.这是为了更高权限的用户向较低特权用户提供帮助,例如当文书用户执行任务并且需要管理员用户在文书用户可以继续之前完成任务时,管理员用户应该能够提升与其权限级别相同的会话,执行管理任务,并将较低权限还原到会话.在没有文书用户注销和管理员用户登录的情况下,我没有看到这样的方法,因为我们希望仅在文书用户的桌面上实现这一点.也许用户切换比整个新会话更整洁,但我非常喜欢Windows认证的Web应用程序的"运行"等效项.

这是否可能,如果是这样,我怎样才能做到这一点?我不知道在哪里开始寻找.

Mat*_*ore 5

允许"超级用户"临时为其他用户设置特定角色,例如使用DateTime设置角色的到期时间.


Dar*_*rov 3

您可以在网站的某个位置放置一个锚点:

@Html.ActionLink("elevate to admin", "SwitchToAdmin", "Home")
Run Code Online (Sandbox Code Playgroud)

然后有一个控制器操作,允许输入管理员凭据:

public ActionResult SwitchToAdmin()
{
    // TODO: Adjust the role name that your administrators will have
    if (!User.IsInRole(@"DOMAIN\Administrators"))
    {
        // The user is not currently an admin => popup a Logon box
        // so that the administrator could authenticate himself
        return new HttpUnauthorizedResult();
    }
    else
    {
        // After inputting the correct username and password for the
        // admin, we can now redirect to the home action and start performing
        // the admin tasks
        return RedirectToAction("index", "home");
    }
}
Run Code Online (Sandbox Code Playgroud)

恢复过程将是相反的。您可以有一个链接,该链接将调用控制器操作,如果用户是管理员,允许普通用户输入其用户名和密码,则该操作将抛出 401。