开发者

File Name in ASP.NET Response Buffer

开发者 https://www.devze.com 2022-12-11 07:09 出处:网络
When doing something like this: Response.Clear(); Response.OutputStream.Write(buffer, 0, buffer.Length);

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消