PRB: Role Parameter Is Case Sensitive for IsInRole Method (816640)



The information in this article applies to:

  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1

SYMPTOMS

In the Microsoft .NET Framework 1.1, you may pass a string as a parameter to the IsInRole method of the GenericPrincipal class or of the WindowsPrincipal class. When you do this, the role parameter is treated as case-insensitive by the IsInRole method when the IsInRole method evaluates the role parameter. This behavior for the IsInRole method has changed from the .NET Framework 1.0. The .NET Framework 1.0 was case-sensitive.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Problem

Note The following code reproduces the behavior only when you are member of the Guests role.
  1. Run Microsoft Visual Studio .NET. Create a Windows Application project.

    By default, Form1 is created.
  2. Add a command button control to the Form1 form.

    Button1 is added to Form1.
  3. Double-click Button1, and then add the following code to the Button1_Click event:

    Microsoft Visual Basic .NET Code
    Dim myDomain As AppDomain = System.Threading.Thread.GetDomain()
    myDomain.SetPrincipalPolicy(Security.Principal.PrincipalPolicy.WindowsPrincipal)
    Dim myPrincipal As System.Security.Principal.WindowsPrincipal = _
       CType(System.Threading.Thread.CurrentPrincipal, System.Security.Principal.WindowsPrincipal)
    MessageBox.Show(myPrincipal.IsInRole("BUILTIN\guests"))
    Microsoft Visual C# .NET Code
    AppDomain myDomain = System.Threading.Thread.GetDomain();
    myDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
    System.Security.Principal.WindowsPrincipal myPrincipal =
       (System.Security.Principal.WindowsPrincipal)System.Threading.Thread.CurrentPrincipal;
    MessageBox.Show((myPrincipal.IsInRole("BUILTIN\\guests")).ToString());
  4. On the Debug menu, click Start to run the application.
  5. Click Button1.

    Notice that False appears.

REFERENCES

For more information about the WindowsPrincipal.IsInRole method, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:2/4/2004
Keywords:kbNameSpace kbProgramming kbfix KB816640 kbAudDeveloper