User.IsInRole returning false

后端 未结 1 387
-上瘾入骨i
-上瘾入骨i 2021-01-18 05:25

My ASP.NET app is using windows authentication. If I run the following code:

WindowsIdentity wi = (WindowsIdentity)User.Identity;

foreach (IdentityReferenc         


        
1条回答
  •  执笔经年
    2021-01-18 06:06

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

    EDIT:
    You need to use this format:

    User.IsInRole(@"DOMAINNAME\rolename")
    

    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:

    
    

    This information comes straight from MSDN. Look at the "Checking Role Membership in Code" section. It's all there.

    0 讨论(0)
提交回复
热议问题