【Web__Cookie】常规使用

2021-03-14 08:32

阅读:512

标签:取值   汉字   bag   var   ons   util   put   time   role   

添加cookie 汉字需UrlEncode

var cookieValue = string.Format("{0}&{1}&{2}", user.Id, HttpUtility.UrlEncode(user.CompanyName), user.RoleId);
HttpCookie Cookie = new HttpCookie(Constant.Manager, cookieValue);
Cookie.Expires = DateTime.Now.AddHours(2);
Response.Cookies.Add(Cookie);

删除cookie

Response.Cookies[Constant.Manager].Expires = DateTime.Now.AddDays(-1);

cookie取值

var cookie = Request.Cookies[Constant.Manager];
if (cookie == null)
{
    return View("login");
}
ViewBag.CompanyName = HttpUtility.UrlDecode(cookie.Value.Split(‘&‘)[1]);

【Web__Cookie】常规使用

标签:取值   汉字   bag   var   ons   util   put   time   role   

原文地址:https://www.cnblogs.com/kikyoqiang/p/12812194.html


评论


亲,登录后才可以留言!