Ian Warburton
Ian Warburton

Reputation: 15716

ASP.net MVC cookie problem

I've got the following code...

private readonly string CookieName = ConfigurationManager.AppSettings["CookieName"];

public void AddCookie(HttpContext context)
{
   var uniqueId = Guid.NewGuid().ToString();

   context.Response.Cookies.Add(new HttpCookie(CookieName, uniqueId));
}

So the cookie arrives at the browser with no value. Any ideas?

Cheers, Ian.

Upvotes: 0

Views: 722

Answers (1)

p.campbell
p.campbell

Reputation: 100607

Are you able to test or refactor the code to use something like this?

HttpCookie c = new HttpCookie("foo");
c.Expires = DateTime.Now.AddDays(99);
c.Values[CookieName] = Guid.NewGuid().ToString();
HttpContext.Current.Response.Cookies.Add(c);

Upvotes: 1

Related Questions