How to secure the ASP.NET_SessionId cookie?

后端 未结 6 2073
难免孤独
难免孤独 2020-12-02 05:58

I have set the .ASPXAUTH cookie to be https only but I am not sure how to effectively do the same with the ASP.NET_SessionId.

The entire site uses HTTPS so there is

6条回答
  •  不知归路
    2020-12-02 06:13

    Found that setting the secure property in Session_Start is sufficient, as recommended in MSDN blog "Securing Session ID: ASP/ASP.NET" with some augmentation.

        protected void Session_Start(Object sender, EventArgs e)
        {
            SessionStateSection sessionState = 
     (SessionStateSection)ConfigurationManager.GetSection("system.web/sessionState");
            string sidCookieName = sessionState.CookieName;
    
            if (Request.Cookies[sidCookieName] != null)
            {
                HttpCookie sidCookie = Response.Cookies[sidCookieName];
                sidCookie.Value = Session.SessionID;
                sidCookie.HttpOnly = true;
                sidCookie.Secure = true;
                sidCookie.Path = "/";
            }
        }
    

提交回复
热议问题