1
我動態創建與它形式的iframe並提交此表格一樣,添加的cookie:無法通過iframe
var iframe = $("<iframe id='download_iframe' style='display: none' src='about:blank'></iframe>");
//...building that form...
form.appendTo(iframe.contents().find('body')).submit();
在URL如該請求轉到我生成一個文件,並設置這樣一個cookie :
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
//...setting content type, disposition and etc...
response.Headers.AddCookies(new[]
{
new CookieHeaderValue("ajaxFileDownload", "true")
{
Expires = DateTimeOffset.Now.AddDays(1),
Domain = Request.RequestUri.Host,
Path = "/",
HttpOnly = false
}
});
所以我預計的cookie集後文件downlod開始,我可以看到標題Set-Cookie
:
Cache-Control:private
Content-Disposition:attachment; filename=engagement_list_28-10-2014.pdf
Content-Length:60027
Content-Type:application/pdf
Date:Tue, 28 Oct 2014 16:12:09 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/7.5
Set-Cookie:ajaxFileDownload=true; expires=Wed, 29 Oct 2014 16:59:35 GMT; domain=localhost; path=/
X-AspNet-Version:4.0.30319
X-MiniProfiler-Ids:["a8e9bef2-d31e-4f41-8896-9222d880544f"]
X-Powered-By:ASP.NET
X-Powered-By:ARR/2.5
X-Powered-By:ASP.NET
但document.cookie
和$("#download_iframe").contents()[0].cookie
是空的我什至不能在瀏覽器的資源中看到該cookie。我做錯了什麼?
頁面http:// about:blank是否會導致跨域問題?我不確定該網頁的工作原理。 – ToastyMallows 2014-10-28 20:36:02