使用的GenericPrincipal实例设置角色 [英] Setting roles by using GenericPrincipal instance
问题描述
最近,我问了一个问题关于如何使用Ajax调用
在asp.net mvc的验证用户,而我得到了我的答案。
Recently I asked a question about how to use ajax calls to authenticate user in asp.net mvc, and I got my answer.
但后来决定使用'角色'的'的GenericPrincipal阶级属性。
But then is decided to use 'Roles' property of 'GenericPrincipal' class
所以我改变了我的code作为跟随遏制角色:
so I changed my code as follow to contain 'Roles':
HttpContext.User = new System.Security.Principal.
GenericPrincipal(new System.Security.Principal.GenericIdentity(login.LoginName),
userRole);
在我的Site.Master的看法,我检查,看看哪一种角色的用户
属于我和显示相应的菜单,但是当我观看
调试期间HttpContext.Current.User.Identity的价值观,
我看到m_roles = STRING [0]和'IsInRole(管理)'返回false。
In my site.master view, I check to see which kind of roles users belongs to and I show appropriate menu, but when I watch 'HttpContext.Current.User.Identity' values during debugging, I see m_roles=string[0] and 'IsInRole("Admin")' returns false.
这怎么可能是固定的?
推荐答案
尝试将当前线程的原则:
Try setting the current thread principle:
System.Threading.Thread.CurrentPrincipal = principal;
如如下所示:
<一href=\"http://social.msdn.microsoft.com/forums/en-US/Vsex$p$pssvcs/thread/5f9735a9-096b-47af-963d-e95130cad6b4\" rel=\"nofollow\">http://social.msdn.microsoft.com/forums/en-US/Vsex$p$pssvcs/thread/5f9735a9-096b-47af-963d-e95130cad6b4
这篇关于使用的GenericPrincipal实例设置角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!