User.IsInRole返回false [英] User.IsInRole returning false
问题描述
我的ASP.NET应用程序使用Windows身份验证。如果我运行下面的code:
My ASP.NET app is using 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";
列表框将包含每个用户所属的组的名称。如果我再打电话 User.IsInRole
,并通过在任何这些团体的名字,我总是得到一个错误。
The listbox will contain the name of every group the user belongs to. If I then call User.IsInRole
, and pass in the name of any of those groups, I always get a false.
谁能告诉我什么,我做错了什么?
Can anyone tell me what I am doing wrong?
感谢
推荐答案
我们需要看到你的web.config。如何处理角色?是角色的经理甚至启用?
We need to see your web.config. How are roles handled? Is the role manager even enabled?
编辑:
您需要使用以下格式:
You need to use this format:
User.IsInRole(@"DOMAINNAME\rolename")
您离开过的域名。如果仍然不能正常工作,请确保你有你的角色提供在web.config中设置:
You are leaving off the domain name. If that still doesn't work, make sure you've got your role provider set in web.config:
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>
此信息直接从 MSDN 来。看看节,在code检查角色成员。这一切都在那里。
This information comes straight from MSDN. Look at the "Checking Role Membership in Code" section. It's all there.
这篇关于User.IsInRole返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!