On WebForms i used to store the role in FormsAuthenticationTicket userdata, however I tried to implement the same method in mvc 5 and it did not work. For some reason
User.Identity.IsAuthenticated
this returns false
var ticket = new FormsAuthenticationTicket(
1,
user.Id.ToString(),
DateTime.Now,
DateTime.Now.AddDays(5),
model.RememberMe,
user.Roles.Select(c => c.Nome).FirstOrDefault(),
FormsAuthentication.FormsCookiePath
);
// Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Name of auth cookie (it's the name specified in web.config) // Hashed ticket
authenticationCookie.Expires = DateTime.Now.AddDays(7);
// Add the cookie to the list for outbound response
Response.Cookies.Add(authenticationCookie);
so since this does not work i used instead
FormsAuthentication.SetAuthCookie(user.Id.ToString(), model.RememberMe);
problem with this is that it does not allow me to have an easy access to the user role so that i can do on a view
if (User.IsInRole("Admin"))
I'm trying to avoid Asp Net Identity because It takes a lot of customization and i don't need all the extra fields nor a password 'cause we authenticate with ldap.
If is there any other option please advice me.