2013-02-11 26 views
3

我們已啓用HttpOnly爲我們的網站。在Asp.Net中啓用HTTPOnly安全

<configuration> 
    <system.web> 
     <httpCookies httpOnlyCookies="true" requireSSL="true" /> 
    </system.web> 
</configuration> 

這是工作正常,當我們訪問非安全區域的網站。但是在安全直播區域(Https)中,這不起作用,我們能夠獲得會話密鑰。如何減輕它。任何想法都會很有幫助。

我試着在Asp.Net 2.0

+0

什麼是「不工作」?你在某處看到錯誤嗎?你沒有看到服務器端的cookie嗎? – tom 2013-02-11 07:05:38

+0

@tom我可以通過JavaScript訪問Sessionid cookie,並且在通過chrome瀏覽器資源部分檢查時未設置httponly。 – kjana83 2013-02-11 07:10:25

+0

您確定您在嘗試之前清除了所有舊餅乾嗎? – Ramesh 2013-02-11 07:13:18

回答

2

我有一堆的解決方案在這裏的傢伙..只是隨意選擇這些解決方案,迎合您的需求

  • 在Global.asax中之中,按如下方式覆蓋Session_Start方法。

    <script runat="server">  
    void Session_Start(object sender, EventArgs e) 
    { 
    
        if(Response.Cookies.Count > 0) 
        foreach(string s in Response.Cookies.AllKeys) 
        if(s == System.Web.Security.FormsAuthentication.FormsCookieName || 
          s.ToLower().Equals("asp.net_sessionid")) 
        Response.Cookies[s].HttpOnly = false; 
    

    }


參考:http://nerd.steveferson.com/2007/09/14/act-sessionid-and-login-problems-with-asp-net-20/#.URiXUqWzd9c

  • 注意,在ASP.NET 1.1中的System.Net.Cookie類不支持 HttpOnly屬性。因此,到的HttpOnly屬性添加到 的cookie,你可以將下面的代碼添加到您的應用程序的

    Application_EndRequest事件處理程序的Global.asax:

    protected void Application_EndRequest(Object sender, EventArgs e) 
    { 
        string authCookie = FormsAuthentication.FormsCookieName; 
    
        foreach (string sCookie in Response.Cookies) 
        { 
         if (sCookie.Equals(authCookie)) 
         { 
           Response.Cookies[sCookie].Path += ";HttpOnly"; 
         } 
        } 
    } 
    



參考:http://blogs.msdn.com/b/dansellers/archive/2006/03/13/550947.aspx

  • 這對您的Global.asax

    void Application_EndRequest(Object sender, EventArgs e) 
    { 
        if (Response.Cookies.Count > 0) 
        { 
         foreach (string s in Response.Cookies.AllKeys) 
         { 
          if (s == "ASP.NET_SessionId") 
          { 
           Response.Cookies["ASP.NET_SessionId"].HttpOnly = false; 
          } 
         } 
        } 
    

    }

添加引用:從這個論壇http://forums.asp.net/p/955272/1177574.aspx#1177574

你也可以試試這個帖子HttpOnly Cookies on ASP.NET 1.1由Scott Hanselman的,但其ASP。 NET 1.1

+0

不,我們嘗試了上述所有四個選項,沒有一個是幫助。 – kjana83 2013-02-13 04:40:14

+0

@bot:我對你的回答感到困惑 - 你爲什麼要把'HttpOnly'設置爲'false'? – 2014-08-18 14:22:55