我有一个.NET项目,我有直接链接下载.mp4到用户硬盘。它在chrome中运行良好,但在IE中,它将其保存为.data文件。有谁知道我怎么解决这个问题?
在我的.aspx页面中,我使用此链接:
<asp:hyperlink Visible="false" id="dlVideo" Font-Size="8pt" NavigateUrl='<%# Eval("VideoName", "~/Workshops/Refology/Get.aspx?FileName={0}&OrigName=" + Eval("FirstName") + "&CamperName=" + Eval("lastname") + "&Topic=" + Eval("Topic"))%>' runat="server" Text='<%# IIf(Eval("VideoName") Is DBNull.Value, "", "Video")%>'></asp:hyperlink>
在Get.aspx.cs页面中是:
protected void Page_Load(object sender, EventArgs e)
{
string videoName = Request.QueryString["FileName"];
string OriginalName = Request.QueryString["OrigName"];
string PersName = Request.QueryString["CamperName"];
string Topic = Request.QueryString["Topic"];
string FinalName = PersName + "-" + OriginalName + "-" + Topic;
Response.Clear();
Response.ContentType = "video/mp4";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FinalName);
Response.TransmitFile(Server.MapPath("~/contents/published/" + videoName));
Response.Flush();
Response.End();
}
答案 0 :(得分:1)
猜测,但可能是因为您在Content-Disposition
标题中免除了文件名的扩展名。此外,如果您的FinalName中有空格,那么您的标题将会混乱;你应该逃避它。 e.g。
/* ... */
var contentDisposition = new System.Net.Mime.ContentDisposition("attachment")
{
FileName = FinalName + ".mp4"
}:
// Properly encode header using ContentDisposition class.
Response.AddHeader("Content-Disposition", contentDisposition.ToString());
ContentDisposition
类可以构建标题,以便您根据需要对其进行编码。