好吧,我有一个ASP.NET MVC 3 RAZOR PAGE,我从服务器端声明了一个cookie:
@{
Request.Cookie["Name1"].Value = "Value1";
}
并且,当我想在客户端使用并更改它时,它的工作可疑
<script type = "text/javascript">
var e
function aa(c) { $.cookie("Name1", c); }
function bb() { e = $.cookie("Name1"); }
</script>
这有问题吗?
答案 0 :(得分:2)
我很确定你需要在响应上设置cookie,而不是在请求上设置:
HttpCookie myCookie = new HttpCookie(CookieName);
myCookie.Values["UserId"] = user.UserId.ToString();
myCookie.Values["LastVisit"] = DateTime.Now.ToString();
myCookie.Expires = DateTime.Now.AddDays(365);
HttpContext.Current.Response.Cookies.Add(myCookie);