开发者

Asp.net generic principal problem

开发者 https://www.devze.com 2023-01-18 11:01 出处:网络
Using this code for authentification: HttpContext.Current.User=new GenericPrincipal (new GenericIdentity(user.UserName), roles);

Using this code for authentification:

HttpContext.Current.User=new GenericPrincipal
  (new GenericIdentity(user.UserName), roles);
FormsAuthentication.SetAuthCookie(user.UserName,false);

Problem is - on next request, HttpContext.Current.User.IsAuthenticated is true, but HttpContext.Current.User.IsInRole("admi开发者_开发知识库n") is false.

There are a lot of info on google but somehow nothing helps as usual.

Tried to add this to my web.config:

<system.web>
  <roleManager enabled="false" />
</system.web>

I do not want to use membership provider.

Any tips?


I think you might be trying to use the wrong kind of Identity if you're using forms authentication. You might be better off using FormsIdentity.

Article on Best Practices for Forms Authentication (might be outdated)


Look like the IsInRole method is on the wrong interface. Try

HttpContext.Current.User.IsInRole("admin")
0

精彩评论

暂无评论...
验证码 换一张
取 消