Microsoft KB Archive/816640

= PRB: Role Parameter Is Case Sensitive for IsInRole Method =

Article ID: 816640

Article Last Modified on 5/12/2007

-

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.



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

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

Button1 is added to Form1.  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(&quot;BUILTIN\guests&quot;)) 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(&quot;BUILTIN\\guests&quot;)).ToString);  On the Debug menu, click Start to run the application. Click Button1.

Notice that False appears.

