Pri*_*ter 6 asp.net-mvc windows-authentication pre-authentication
让我解释一下:应用程序已经在使用Windows集成安全性,而不是Forms.我想要完成的是所谓的"升级"身份验证,或针对以下场景的"强制重新身份验证":
这样可以防止以下两个问题:
我知道,有些人会认为这是"偏执狂",但有些人会说它是常识,应该在某个地方构建(jQuery或.NET)
我真的很感激任何输入.谢谢!
让表单将凭据与请求一起发送以执行该操作,即某些操作要求您提供用户名/密码。使用PrincipalContext ValidateCredentials方法来确保已输入正确的凭据,并检查提供的用户名是否与User.Identity对象中的当前用户名匹配。
public ActionResult SensitiveAction( SensitiveModel model, string username, string password )
{
using (var context = new PrincipalContext(ContextType.Domain))
{
if (!string.Equals(this.User.Identity.Name,username,StringComparison.OrdinalIgnoreCase)
|| !context.ValidateCredentials(username,password))
{
return View("PermissionDenied");
}
}
...
}
Run Code Online (Sandbox Code Playgroud)