我有一个运行ASP.NET MVC的小型web服务器。服务器正在以用户"abc“运行,但用户"abc”对ActiveDirectory中的“更改”没有权限。
所以我必须将PrincipalContext中的用户登录信息传递给。
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, null, user, password))
{
GroupPrincipal theGroup = GroupPrincipal.FindByIdentity(context, groupId);
theGroup.Members.Add(context, IdentityType.SamAccountName, userId);
theGroup.Save();
}代码是有效的。但我不喜欢将密码从Methode传递给Methode...MVC上的=>我有一个单点登录,服务器知道我
System.Web.HttpContext.Current.User.Identity是否可以使用此信息?
new PrincipalContext(ContextType.Domain, null, [System.Web.HttpContext.Current.User]) ???或者我必须给你密码。以及如何最好地从视图传递到此方法。
谢谢
发布于 2018-11-22 22:51:52
这被称为“模仿”。只要您使用的是Windows身份验证,就可以使用WindowsIdentity.Impersonate()方法进行身份验证:
using (var ctx = ((WindowsIdentity) HttpContext.Current.User.Identity).Impersonate()) {
// Anything done here will use the user's credentials
using (var context = new PrincipalContext(ContextType.Domain)) {
...
}
}https://stackoverflow.com/questions/53425083
复制相似问题