參考網址:https://www.cnblogs.com/Irving/archive/2013/03/08/2949106.html
c#
System.Web.Security.FormsAuthenticationTicket tk = new FormsAuthenticationTicket(1,
sUT.UserID.ToString(),
DateTime.Now,
DateTime.Now.AddDays(1),
true,
"",
System.Web.Security.FormsAuthentication.FormsCookiePath
);
string key = System.Web.Security.FormsAuthentication.Encrypt(tk); //得到加密后的身份驗證票字串
HttpCookie ck = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, key);
//ck.Domain = System.Web.Security.FormsAuthentication.CookieDomain; // 這句話在部署網站后有用,此為關系到同一個域名下面的多個站點是否能共享Cookie
ck.HttpOnly = true;//cookie添加HttpOnly屬性
// ck.Secure = true;//cookie添加Secure安全驗證
ck.Secure = FormsAuthentication.RequireSSL;//cookie添加Secure安全驗證
HttpContext.Current.Response.Cookies.Add(ck);