Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从asp.net FormsAuthentication对象获取与用户关联的角色?_C#_Asp.net_Forms Authentication_Roles - Fatal编程技术网

C# 如何从asp.net FormsAuthentication对象获取与用户关联的角色?

C# 如何从asp.net FormsAuthentication对象获取与用户关联的角色?,c#,asp.net,forms-authentication,roles,C#,Asp.net,Forms Authentication,Roles,如何从asp.net FormsAuthentication对象获取与用户关联的角色?除了IsInRole,我看不到任何有用的方法 在这方面。我正在寻找类似GetRoles()的内容。我只使用User.IsInRole(“rolename”),需要循环使用 我的角色找到我的iterest角色。 有没有办法从Formsauthticket本身获取角色?实际上,获取用户角色的代码可以是: Roles.GetRolesForUser(WebSecurity.CurrentUserName); 我为您

如何从asp.net FormsAuthentication对象获取与用户关联的角色?除了IsInRole,我看不到任何有用的方法 在这方面。我正在寻找类似GetRoles()的内容。我只使用User.IsInRole(“rolename”),需要循环使用 我的角色找到我的iterest角色。
有没有办法从Formsauthticket本身获取角色?

实际上,获取用户角色的代码可以是:

Roles.GetRolesForUser(WebSecurity.CurrentUserName);
我为您提供了
WebSecurity.CurrentUserName
以获取当前用户的用户名

您可以尝试使用其他方法,如:

Roles.GetRolesForUser("afzaal_ahmad_zeeshan")
其中,afzaal_ahmad_zeeshan是您想要获得角色的用户的用户名

还要注意,这为您提供了一个
String[]
数组,因此使用
foreach()
循环可能是过滤结果的解决方案


有关更多信息:

您是否查看了
角色。GetRolesForUser()
?请检查此项,以便问答:您也可以检查此项,以便将角色保存在票证中: