如何获取Content-Disposition来处理引用的文件名?

时间:2017-07-05 22:12:54

标签: c# http http-headers content-disposition

我正在尝试为需要周围引号的Android下载定义文件名。似乎ContentDisposition.ToString()无法正确处理转义字符。

string path = "User.pdf";   
var cd_escaped = new System.Net.Mime.ContentDisposition()
{
    FileName = $"\"{path}\""
};
var cd_normal = new System.Net.Mime.ContentDisposition()
{
    FileName = path
};

// Content-Disposition:attachment; filename="\"User.pdf\""
Response.AppendHeader("Content-Disposition", cd_escaped.ToString());
// Content-Disposition:attachment; filename=User.pdf
Response.AppendHeader("Content-Disposition", cd_normal.ToString());

我有更复杂的ContentDisposition对象,我不想手动构建,但仍然可以用引号括起来。我怎么能这样做?

0 个答案:

没有答案