当用户点击我的链接时,它会弹出另存为对话框,但它想要在IE以外的任何浏览器中将其另存为ashx文件。该文件是从数据库获取的标准jpeg。这会导致什么呢?
string id = ctx.Request.QueryString["id"];
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand("EBig", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@EID", id);
byte[] pict = null;
ctx.Response.ContentType = "image/pjpeg";
try
{
con.Open();
pict = (byte[])cmd.ExecuteScalar();
ctx.Response.Clear();
ctx.Response.AppendHeader("content-disposition", "attachment;");
ctx.Response.ContentType = "image/pjpeg";
ctx.Response.BinaryWrite(pict);
ctx.Response.Flush();
ctx.Response.End();
}
catch
{
}
finally
{
con.Close();
}发布于 2011-04-07 02:34:10
Hanselman has a post在这上面。它涉及到在Content-Disposition响应头上设置一个名为filename的附加属性。
相关RFC is here,相关部分为2.3:
如果实体被分离并存储在单独的文件中,发送者可能希望建议要使用的文件名。如果接收MUA将实体写入文件,则建议的文件名应用作实际文件名的基础,只要有可能。
发布于 2011-04-07 02:36:43
您需要添加文件名:
context.Response.AppendHeader("Content-Disposition",
string.Format("attachment;filename={0}", yourFileName));https://stackoverflow.com/questions/5571258
复制相似问题