create cookies in MVC4 rasor c#
  • Hi please how we can create cookies in MVC4 rasor c#. thank you so much friends :) .
  • 1 Comment sorted by
  • public ActionResult Create()
    {
    HttpCookie cookie = new HttpCookie("Cookie");
    cookie.Value = "Hello Cookie! CreatedOn: " + DateTime.Now.ToShortTimeString();

    this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
    return RedirectToAction("Index", "Home");
    }

    public ActionResult Remove()
    {
    if (this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains("Cookie"))
    {
    HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies["Cookie"];
    cookie.Expires = DateTime.Now.AddDays(-1);
    this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
    }
    return RedirectToAction("Index", "Home");
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

    Optimum Creative