MVC FilePathResult操作导致Chrome中的重复请求
本文关键字:请求 Chrome FilePathResult 操作 MVC | 更新日期: 2023-09-27 17:59:55
我有一个MVC操作,调用如下:
http://localhost/Report/PrintContainerMasterTrayList?containerMasterId=x&type=downloadview
动作具有以下特征
public ActionResult PrintContainerInstanceTrayList(int containerInstanceId, string type)
返回如下FilePathResult:
return File(filename, "application/pdf");
这一切都很好,只是在Chrome中请求会触发两次。该请求在Firefox和IE11中只发出一次。
原始请求
GET http://localhost/DEV-SAF/Report/PrintContainerMasterTrayList?containerMasterId=x&type=downloadview HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en;q=0.8
Cookie: .ASPXANONYMOUS=-
第二个请求
GET http://localhost/DEV-SAF/Report/PrintContainerMasterTrayList?containerMasterId=x&type=downloadview HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36
Accept: */*
Referer: http://localhost/DEV-SAF/Report/PrintContainerMasterTrayList?containerMasterId=x&type=downloadview
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en;q=0.8
来自两个请求的响应是相同的(在这种情况下,最高可达使用过多带宽的4Mb文件)。
是什么导致了这种行为?
编辑
第一个请求的响应是HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/pdf
Server: Microsoft-IIS/10.0
Set-Cookie: .AUTH=xxxxxx; path=/; HttpOnly
X-AspNetMvc-Version: 5.2
Date: Wed, 03 Aug 2016 14:17:41 GMT
Content-Length: 3999
第二个请求的响应是HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/pdf
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 5.2
Date: Wed, 03 Aug 2016 14:17:46 GMT
Content-Length: 3999
尝试在Action中添加Content-Disposition标头以响应以下内容"attachment;filename=test.pdf"或简单的"attachmentary"
Response.AppendHeader("Content-Disposition", "attachment");