我有一個在domain1.mywebsite.com上創建cookie的ASP.Net應用程序。從不同子域讀取Cookie數據
Private Sub CreateCookie()
If Request.Cookies("D1_MyWebSite") Is Nothing Then
Dim aCookie As New HttpCookie("D1_MyWebSite")
aCookie.Path = "/"
aCookie.Value = DateTime.Now.ToUniversalTime.ToString
aCookie.Expires = DateTime.Now.AddMinutes(10)
Response.Cookies.Add(aCookie)
Else
Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies("D1_MyWebSite")
cookie.Value = DateTime.Now.ToUniversalTime.ToString
cookie.Expires = DateTime.Now.AddMinutes(10)
Response.Cookies.Add(cookie)
End If
End Sub
在domain2.mywebsite.com上,我試圖讀取使用jQuery保存在cookie中的值。 網頁地址是domain2.mywebsite.com/index.html但我的.js此頁面文件的來源是:
<script type="text/javascript" src="https://domain1.mywebsite.com/js/jumppage.js"></script>
<script src="https://domain1.mywebsite.com/js/jquery.cookie.js"></script>
我試着用下面來獲取域1的值。 mywebsite.com D1_MyWebSite cookie,但它所做的只是爲domain2.mywebsite.com創建一個名爲D1_MyWebSite的新cookie。我如何獲取domain1.mywebsite.com D1_MyWebSiteCookie的cookie值?
$.cookie("D1_MyWebSite", "value");
更新:我已經取代aCookie.Path =「/」與aCookie。域= 「mywebsite.com」。現在我已經完成了它,它爲mywebsite.com創建了一個cookie,但我仍然無法通過jQuery訪問它。我的jQuery代碼繼續爲domain2.mywebsite.com創建一個D1_MyWebSite cookie。 – crjunk