How to set cookie value in C#?

Total Post:108

C#  Cookies 
 966  View(s)
Rate this:
I am getting problem to set cookie value, my code is below:
public ActionResult sellerLogin(string userid,string password)
int count = db.userinfo.Count(p => p.userId == userid && p.password == password);
if (count == 1)
  HttpCookie userinfoid = new HttpCookie("userinfoid");
  userinfoid["uerinfoid"] = userid.ToString();
  return View("loginSuccess");
return View();

In the above code I have set the value in the cookie but when I access that value in the viewbag from another view controller I can't find that value.
Please help me, how to set or get the cookie value.
  1. Post:214

    Re: How to set cookie value in C#?

    You can set the cookie value like this:
    because Response.Cookie.Add() is use to add multiple cookies whereas SetCookie will update an existing cookie.

    Or, you can add logic that will check the cookie is already exists or not if yes then use Response.SetCookie else Response.Cookie.Add.
    I hope it will be helpful for you.

      Modified On Jun-16-2016 11:57:29 PM