User.IsInRole returns false

My ASP.NET application uses Windows Authentication. If I run the following code:

WindowsIdentity wi = (WindowsIdentity)User.Identity; foreach (IdentityReference r in wi.Groups) { ListBox1.Items.Add(r.Translate (typeof (NTAccount)).Value); } if (User.IsInRole ("Everyone")) Label1.Text = "Is in role"; 

The list will contain the name of each group to which the user belongs. If I then call User.IsInRole and pass the name of any of these groups, I always get false.

Can someone tell me what I am doing wrong?

thanks

+6
security
source share
1 answer

We need to see your web.config. How are roles handled? Is role manager enabled?

EDIT:
You should use this format:

 User.IsInRole(@"DOMAINNAME\rolename") 

You are leaving the domain name. If this still does not work, make sure you have the role provider installed in web.config:

 <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/> 

This information comes directly from MSDN . See the section "Verifying the Membership Role in Code". It is all there.

+7
source share

All Articles