When doing something like this:
Response.Clear();
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.ContentType = "audio/mpeg";
Response.Flush();
The downloaded file name is "Default.aspx". How can I change it to something like 开发者_运维百科"a.mp3"?
var cd = new ContentDisposition
{
FileName = "file.mp3"
};
Response.AddHeader("Content-Disposition", cd.ToString());
ContentDisposition is a convenient class that allows you to set the Content-Disposition header in a friendly manner, without knowing the internals of the HTTP protocol. Of course you could always set the header manually if you prefer:
Response.AppendHeader("Content-Disposition", "attachment; filename=file.mp3");
精彩评论