in my authController / signin controller i have this code:
entities.UserAccount user = (new BLL.GestionUserAccount()).authentifier(email, password); //storing the userId in a cookie string roles = (new BLL.GestionUserAccount()).GetUserRoles(user.IdUser); // Initialize FormsAuthentication, for what it worth FormsAuthentication.Initialize(); // FormsAuthentication.SetAuthCookie(user.IdUser.ToString(), false); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // Ticket version user.IdUser.ToString(), // Username associated with ticket DateTime.Now, // Date/time issued DateTime.Now.AddMinutes(30), // Date/time to expire true, // "true" for a persistent user cookie roles, // User-data, in this case the roles FormsAuthentication.FormsCookiePath);// Path cookie valid for // Encrypt the cookie using the machine key for secure transport string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie( FormsAuthentication.FormsCookieName, // Name of auth cookie hash); // Hashed ticket // Get the stored user-data, in this case, our roles // Set the cookie expiration time to the tickets expiration time if (ticket.IsPersistent) cookie.Expires = ticket.Expiration; // Add the cookie to the list for outgoing response Response.Cookies.Add(cookie); return RedirectToAction("index", "Home");
I have a menu on the main page, in this menu there is an element that is designed to view only the administrator role.
<% if (HttpContext.Current.User.IsInRole("admin")){ %> <%=Html.ActionLink("Places", "Places", "Places")%> <%} %>
even with the HttpContext.Current.User defining the correct roles, I cannot see the element:

globalx asax:
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated) { if (HttpContext.Current.User.Identity is FormsIdentity) { FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity; FormsAuthenticationTicket ticket = id.Ticket;
user594166
source share