net网站mvc架构怎么用js cookie获取用户id
1个回答
展开全部
设置cookie可以直接使用
HttpCookie cookie = new cookie = new HttpCookie(COOKIE_NAME_FOR_USER);
cookie.Expires = DateTime.Now.AddYears(1);
cookie[COOKIE_USER_NAME] = "用户名";
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
取:
HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get(COOKIE_NAME_FOR_USER);
删除:
System.Web.HttpContext.Current.Request.Cookies.Remove(COOKIE_NAME_FOR_USER);
另外,判断是否有cookie可以直接使用取的cookie和null进行比较,如果取出来非null就说明不为空
HttpCookie cookie = new cookie = new HttpCookie(COOKIE_NAME_FOR_USER);
cookie.Expires = DateTime.Now.AddYears(1);
cookie[COOKIE_USER_NAME] = "用户名";
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
取:
HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get(COOKIE_NAME_FOR_USER);
删除:
System.Web.HttpContext.Current.Request.Cookies.Remove(COOKIE_NAME_FOR_USER);
另外,判断是否有cookie可以直接使用取的cookie和null进行比较,如果取出来非null就说明不为空
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询