I seem to be having a problem with using IsInRole.
if (Page.User.IsInRole("User")) {
Response.Write("In group");
} else {
Response.Write("Not in group");
}
It does not seem to matter what string that I place in the function it always comes as false.
I tried this piece of code:
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
Response.Write("Thread User is: " + myPrincipal.Identity.Name.ToString());
Array wbirFields = Enum.GetValues(typeof(WindowsBuiltInRole));
foreach (object roleName in wbirFields) {
try {
Response.Write(roleName + " : " + myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
}
catch (Exception) {
Response.Write("Could not obtain role for this " + roleName);
}
}
if (myPrincipal.IsInRole("User")) {
Response.Write("In group");
} else {
Response.Write("Not in group");
}
Administrator : True User : True Guest : False PowerUser : False Could not obtain role for AccountOperator Could not obtain role for this SystemOperator Could not obtain role for this PrintOperator BackupOperator : False Could not obtain role for this Replicator
Not in group
Although the first bit of code said that true for 'User' the second reported false.
The problem is that I do not want to check against a Windows built in role for groups that has design for my pupose. Each role will depend if some controls are read only or not.
Cheers
Robert T Turner