Cookies are created just like in plain old ASP.NET, you just need to access Response
.
public ActionResult Login(string username, string password, bool rememberMe) {
However, if you use Forms Auth, you can simply save the FormsAuth cookie:
public ActionResult Login(string username, string password, bool rememberMe) {
You can read cookies as follows:
public ActionResult Index() { var cookie = Request.Cookies["RememberUsername"]; var username = cookie == null ? string.Empty : cookie.Value;
If you use forms authentication and the user is logged in, you can access their username as follows:
public ActionResult Index() { var username = User.Identity.IsAuthenticated ? User.Identity.Name : string.Empty;
You can decrypt and read the contents of the ticket. You can even store small amounts of user data on a ticket if you need to. See this article for more information.
source share