asp.net(c#)下载文件时电脑安装迅雷后下载的是页面文件

来源:百度知道 编辑:UC知道 时间:2024/05/14 00:21:25
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
con.Open();
string sql = "select * from scwd where id='" + GridView2.SelectedRow.Cells[0].Text + "'";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
Response.Buffer = true;
Page.Response.Clear();//清除缓冲区所有内容
Page.Response.ContentType = "application/octet-stream";
Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(sdr["mc"].ToString()));
byte[] file = (Byte[])sdr["wd"];//读出数据
int a = file.Length;
Response.BinaryWrite(file);
Response.Flush();
Response.End();
sdr.Close();
con.Close();
以上代码是下载的

我也遇到了这种情况。用360安全卫士把讯雷的监视插件清理掉就可以了。
或者下载的时候不要点保存,点打开,然后再保存,也可以的。

这样做本来就错了。。。

ASP.NET下载最好的方式是分开服务器,把数据库和文件服务器分开。

你数据库里要保存的是下载地址,而不是文件。