让我说:
点击第一个链接弹出“保存为”框,然后单击“取消”。接下来,
点击第二个链接弹出“保存为”框,然后单击“取消”。接下来,
点击第三个链接弹出“保存为”框,然后单击“取消”。
目前,弹出框不显示,页面与忙碌相同!
条件刚好在win7。在XP中没问题。
抱歉我的英语不好! 的Index.aspx:
<a href="ShowFile.aspx?fileID=1" >download</a>
<a href="ShowFile.aspx?fileID=2" >download</a>
<a href="ShowFile.aspx?fileID=3">download</a>
<a href="ShowFile.aspx?fileID=4" >download</a>
ShowFile.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, "1.doc", @"d:\1.doc", 1024000);
if (!success)
Response.Write("dowload error!");
Page.Response.End();
}
public static bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed)
{
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes");
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0;
double pack = 10240; //10K bytes
//int sleep = 200; //
int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
//Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));
br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Floor((fileLength - startBytes) / pack) + 1;
for (int i = 0; i < maxCount; i++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString())));
Thread.Sleep(sleep);
}
else
{
i = maxCount;
}
}
}
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}
答案 0 :(得分:1)
通常当您创建用于下载文件的页面时,最好使用处理程序,或者至少在其aspx页面禁用会话时。
原因是因为会话锁定用户直到完成,并且当您下载文件时通常需要很长时间,或者如果您停止它,则可以堆叠直到理解网络已关闭。
因此禁用此aspx页面的会话可以解决您的问题。
相对:
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely
Trying to make Web Method Asynchronous