net网站mvc架构怎么用js cookie获取用户id?

net网站mvc架构怎么用js cookie获取用户id


摇曳的蔷薇
浏览 517回答 1
1回答

慕娘9325324

设置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就说明不为空
打开App,查看更多内容
随时随地看视频慕课网APP