你跟踪一下看看MyIdentity.Name是什么?在看看MyIdnetity.IsSystem是不是true?
如果回答是肯定的,那就是你的“User“不正确,IsInRole中的参数必须写成 xxxx\User的形式,或者WindowsBuiltInRole枚举的成员,或者对应该枚举的整型。
如果回答是肯定的,那就是你的“User“不正确,IsInRole中的参数必须写成 xxxx\User的形式,或者WindowsBuiltInRole枚举的成员,或者对应该枚举的整型。
AppDomain myDomain = Thread.GetDomain(); myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
Console.WriteLine("{0} belongs to: ", myPrincipal.Identity.Name.ToString()); Array wbirFields = Enum.GetValues(typeof(WindowsBuiltInRole)); foreach (object roleName in wbirFields)
{
try
{
Console.WriteLine("{0}? {1}.", roleName,
myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
}
catch (Exception)
{
Console.WriteLine("{0}: Could not obtain role for this RID.",
roleName);
}
}
IsInRole(“xxxx\User”)这样的参数形式我也试过了
但是返回的结果还是false!!