Reputation: 381
I was wondering how to implement cookie based authentication for a mvc .net framework application. I've used .net core and I've seen how easy it is to implement but I'm not sure how to do this for .net framework.
I tried googling but haven't seen many examples, anyone any sample code?
Upvotes: 0
Views: 136
Reputation: 299
You Can take the sample of code and implement inside your ActionMethod
in Asp.Net Framework.
string userData = "A,V";
FormsAuthenticationTicketticket = new FormsAuthenticationTicket(
login.First().Name,
userData,
FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.HttpOnly = true;
Response.Cookies.Add(cookie);
Upvotes: 1