Pur*_*sai 113 pdf google-chrome http-headers
从服务器收到重复的标头
来自服务器的响应包含重复的标头.此问题通常是配置错误的网站或代理的结果.只有网站或代理管理员才能解决此问题.
错误349(net :: ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION):收到多个不同的Content-Disposition标头.不允许这样做以防止HTTP响应分裂攻击.
我在chrome中导出为pdf时发现了这个错误.
Response.Buffer = false;
Response.ClearHeaders();
string ext = objProp.PACKAGEFILENAME.Substring(objProp.PACKAGEFILENAME.LastIndexOf("."));
string ext1 = ext.Substring(1);
Response.ContentType = ext1;
Response.AddHeader("Content-Disposition", "target;_blank,attachment; filename=" + objProp.PACKAGEFILENAME);
const int ChunkSize = 1024;
byte[] binary = objProp.PACKAGEDOCUMENT;
System.IO.MemoryStream ms = new System.IO.MemoryStream(binary);
int SizeToWrite = ChunkSize;
for (int i = 0; i < binary.GetUpperBound(0) - 1; i = i + ChunkSize)
{
if (!Response.IsClientConnected) return;
if (i + ChunkSize >= binary.Length) SizeToWrite = binary.Length - i;
byte[] chunk = new byte[SizeToWrite];
ms.Read(chunk, 0, SizeToWrite);
Response.BinaryWrite(chunk);
Response.Flush();
}
Response.Close();
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
Bry*_*rts 224
这有点旧,但谷歌排名很高,所以我想我会从Chrome中找到答案,pdf显示,从服务器收到的重复标题
基本上我的问题还在于文件名包含逗号.用逗号代替删除它们你应该没问题.我创建有效文件名的功能如下.
public static string MakeValidFileName(string name)
{
string invalidChars = Regex.Escape(new string(System.IO.Path.GetInvalidFileNameChars()));
string invalidReStr = string.Format(@"[{0}]+", invalidChars);
string replace = Regex.Replace(name, invalidReStr, "_").Replace(";", "").Replace(",", "");
return replace;
}
Run Code Online (Sandbox Code Playgroud)
tom*_*omc 92
服务器应该在文件名周围加上双引号,正如@cusman和@Touko在回复中提到的那样.
例如:
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
Run Code Online (Sandbox Code Playgroud)
只需在您的文件名周围加上一对双引号,如下所示:
this.Response.AddHeader("Content-disposition", $"attachment; filename=\"{outputFileName}\"");
小智 5
对我来说,问题是关于逗号不在文件名中,但如下: -
Response.ok(streamingOutput,MediaType.APPLICATION_OCTET_STREAM_TYPE).header("content-disposition"," attachment,filename = your_file_name").build();
附件后我不小心写了一个逗号.通过用分号替换逗号来解决它.
| 归档时间: |
|
| 查看次数: |
101190 次 |
| 最近记录: |