protected void Page_Load(object sender, EventArgs e) { if (!User.Identity.IsAuthenticated) { Response.Redirect("~/Account/Login"); } else { myIsAdmin = new PrincipalManager().IsAdminByUserName(User.Identity.Name); } }
/// <summary> /// /// </summary> /// <param name="currentUser"></param> /// <param name="user"></param> /// <param name="appID"></param> /// <param name="overrideID"></param> /// <param name="userID"></param> /// <returns></returns> public string[] GetUserRoles(string currentUser, string user, string appID, string overrideID, string userID, Guid?applicationCode) { // Create instance of ADRoleLookup repository IRepository <ADRoleLookup> adRoleLookupRepository = new Repository <ADRoleLookup>(currentUser, user, appID, overrideID); IRepository <StaffAttributes> staffAttributesRepository = new Repository <StaffAttributes>(currentUser, user, appID, overrideID); IRepository <Staff> staffRepository = new Repository <Staff>(currentUser, user, appID, overrideID); IPrincipalManager principalManager = new PrincipalManager(); IActiveDirectoryHelper activeDirectoryHelper = new ActiveDirectoryHelper(staffRepository, principalManager); // Call overload with injected objects return(GetUserRoles(currentUser, user, appID, overrideID, userID, applicationCode, adRoleLookupRepository, staffAttributesRepository, activeDirectoryHelper)); }
protected void Application_AuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { // Get the forms authentication ticket. FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); var identity = new GenericIdentity(authTicket.Name, "Forms"); var principal = new PrincipalManager(identity); // Get the custom user data encrypted in the ticket. string userData = ((FormsIdentity)(Context.User.Identity)).Ticket.UserData; // Deserialize the json data and set it on the custom principal. var serializer = new JavaScriptSerializer(); principal.User = (User)serializer.Deserialize(userData, typeof(User)); // Set the context user. Context.User = principal; } }