user2661305
user2661305

Reputation: 381

Cookie Based Authentication

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

Answers (1)

Surendra Singh
Surendra Singh

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

Related Questions