ASP.net MVC cookie问题

时间:2011-05-31 15:33:50

标签: asp.net-mvc-3 session-cookies

我有以下代码......

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

因此cookie以 no 值到达浏览器。有什么想法吗?

干杯,伊恩。

1 个答案:

答案 0 :(得分:1)

您是否可以测试或重构代码以使用类似的内容?

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