你跟踪一下看看MyIdentity.Name是什么?在看看MyIdnetity.IsSystem是不是true?
如果回答是肯定的,那就是你的“User“不正确,IsInRole中的参数必须写成 xxxx\User的形式,或者WindowsBuiltInRole枚举的成员,或者对应该枚举的整型。

解决方案 »

  1.   

    补充:xxxx可以是BUILTIN,域名或者机器名,下面是一段来自msdn的代码(使用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);
           }
            }
      

  2.   

    我也试过用IsSystem 是false
    IsInRole(“xxxx\User”)这样的参数形式我也试过了
    但是返回的结果还是false!!