cookie設置HttpOnly、Secure屬性


參考網址: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);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM