Created
April 22, 2016 14:17
-
-
Save avisser/382e6d51450699fbb766e8a9b741e564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PutInGlobalAsaxCS { | |
protected void Application_PostAuthenticateRequest() | |
{ | |
var user = HttpContext.Current.User as WindowsPrincipal; | |
if (user != null) | |
{ | |
HttpContext.Current.User = new SpecPrincipal((WindowsIdentity) user.Identity); | |
} | |
} | |
} | |
public class SpecPrincipal : WindowsPrincipal | |
{ | |
public SpecPrincipal(WindowsIdentity ntIdentity) : base(ntIdentity) | |
{ | |
} | |
public override bool IsInRole(string role) | |
{ | |
var roleMgr = DependencyResolver.Current.GetService<ApplicationRoleManager>(); | |
var userMgr = DependencyResolver.Current.GetService<ApplicationUserManager>(); | |
var user = userMgr.GetCurrentUser(); | |
var rolesForUser = roleMgr.GetRolesForUser(user.Id); | |
return rolesForUser.Select(r => r.Name).Contains(role); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment