File name in ASP.NET response buffer

By doing something like this:

Response.Clear();

Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.ContentType = "audio/mpeg";
Response.Flush();

The loaded file name is "Default.aspx". How can I change it to something like "a.mp3"?

+3
source share
1 answer
var cd = new ContentDisposition 
{
    FileName = "file.mp3"
};
Response.AddHeader("Content-Disposition", cd.ToString());

ContentDisposition is a convenient class that allows you to set Content-Disposition in a friendly manner, without knowing the internal components of the HTTP protocol. Of course, you can always adjust the title manually if you want:

Response.AppendHeader("Content-Disposition", "attachment; filename=file.mp3");
+7
source

Source: https://habr.com/ru/post/1722218/


All Articles