开发者

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 cooki开发者_如何学编程e arrives at the browser with no value. Any ideas?

Cheers, Ian.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜