我想使用WCF做一些远程用户管理的事情。我重复使用了我在server 2003上的一些代码,并且运行良好,但是在我的Windows 7测试框中,当我查看调用该函数的用户是否是管理员时,它说这不是。WCF模拟不模仿管理员
[OperationBehavior(Impersonation=ImpersonationOption.Required)]
public string SetPassword(string username)
{
WindowsPrincipal principal = new WindowsPrincipal(OperationContext.Current.ServiceSecurityContext.WindowsIdentity);
System.Diagnostics.Debug.Print(WindowsIdentity.GetCurrent().Name);
System.Diagnostics.Debug.Print(principal.Identity.Name);
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
{
//try
{
lock (Watchdog.m_principalContext)
{
using (UserPrincipal up = UserPrincipal.FindByIdentity(Watchdog.m_principalContext, username))
{
string newpassword = CreateRandomPassword();
up.SetPassword(newpassword);
up.Save();
return newpassword;
}
}
}
//catch
{
return null;
}
}
else
throw new System.Security.SecurityException("User not administrator");
}
principal.IsInRole(WindowsBuiltInRole.Administrator)
每次都返回false。我目前的身份和主要身份都是被冒充的正确用户。并且该用户是管理员用户组的成员。
我认为它与在Windows Vista和Windows Vista中实现的UAC有关。这将是一个问题,因为这将会是一个win2k8-r2盒子。
关于怎么做的任何建议?
您是否在操作级别使用基于属性的权限需求进行了调查? [PrincipalPermission(SecurityAction.Demand,角色= “管理员”)] – kd7 2010-10-07 18:14:37
@Scott Chamberlin我问一个相关的问题,请你检查一下:http://stackoverflow.com/questions/18842970/asp-net-imperonate-in- netframework -2- VS-netframework -4- – 2013-09-17 07:26:10