📜  使用创建 guid 自动为未登录用户登录用户并设置为 cookie - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:05.984000             🧑  作者: Mango

代码示例1
string cookieValue = Guid.NewGuid().ToString();
//Creating a cookie which has the name "UserId"
HttpCookie userIdCookie = new HttpCookie("userId");
userIdCookie.Value = cookieValue;
//This is where you would state how long you would want the cookie on the client. In your instance 2 days later.
userIdCookie.Expires = DateTime.Now.AddDays(3);
Response.SetCookie(userIdCookie);