protected void Application_AuthenticateRequest(Object sender, EventArgs e) { string name = String.Empty; HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); name = authTicket.Name; } var identity = new CustomIdentity(name, "Forms"); var principal = new CustomPrincipal(identity); Context.User = principal; }
public static bool IsCurrentUserId(this Controller controller, Guid userId) { CustomIdentity identity = new CustomIdentity(controller.HttpContext.User.Identity); return identity.User.Id == userId; }