开发者

ASP.net MVC cookie problem

开发者 https://www.devze.com 2023-03-09 06:30 出处:网络
I\'ve got the following code... private readonly string CookieName = ConfigurationManager.AppSettings[\"CookieName\"];

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

精彩评论

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