protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { if (FormsAuthentication.CookiesSupported == true) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; string[] roles = new string[10]; var uow = new UnitOfWork(); Users user = uow.UserRepository.Get(filter: u => u.Name == username).FirstOrDefault(); roles[0] = user.Role.ToString(); HttpContext.Current.User = new System.Security.Principal.GenericPrincipal( new System.Security.Principal.GenericIdentity(username, "Forms"), roles); } catch (Exception) { } } } }
public AccountController(UnitOfWork uow) { unitOfWork = uow; }