我正在尝试为需要周围引号的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对象,我不想手动构建,但仍然可以用引号括起来。我怎么能这样做?