我正在使用 MVC 5 + Windows 身份验证 + 自定义角色,像这样
protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
List<string> roles = db.GetRoles(HttpContext.Current.User.Identity.Name);
System.Security.Principal.GenericPrincipal ppl = new System.Security.Principal.GenericPrincipal(HttpContext.Current.User.Identity, roles.ToArray());
HttpContext.Current.User = ppl;
}
一切正常,意味着我可以做到
if (HttpContext.Current.User.IsInRole("SomeRole"))
{
//do my stuff
}
我的问题是如何检索用户的所有角色?请记住,我没有使用 RoleManager。