Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在firefox中下载文件后重置ASP.NET TCP_Asp.net - Fatal编程技术网

在firefox中下载文件后重置ASP.NET TCP

在firefox中下载文件后重置ASP.NET TCP,asp.net,Asp.net,所以我对此束手无策,一直在寻找答案。我有一个ASP.NET3.5应用程序,它有一个允许用户下载和查看存储在数据库中的文件的功能。在用户单击链接下载文件,然后单击站点中的任何其他链接后,他们会看到Firefox的黄色屏幕(XML解析错误:元素格式不正确…),我知道当Firefox获得空白页面时会发生这种情况。不过在IE中效果很好 在尝试了几乎所有的方法之后(在一个新的窗口中打开一个通用的http处理程序的下载处理,在文件下载后清除响应缓冲区/before/both,在下载后清除响应头),我查看了H

所以我对此束手无策,一直在寻找答案。我有一个ASP.NET3.5应用程序,它有一个允许用户下载和查看存储在数据库中的文件的功能。在用户单击链接下载文件,然后单击站点中的任何其他链接后,他们会看到Firefox的黄色屏幕(XML解析错误:元素格式不正确…),我知道当Firefox获得空白页面时会发生这种情况。不过在IE中效果很好

在尝试了几乎所有的方法之后(在一个新的窗口中打开一个通用的http处理程序的下载处理,在文件下载后清除响应缓冲区/before/both,在下载后清除响应头),我查看了HttpFox中的头,它说它得到了一个中止或其他东西。然后,当wireshark中发生错误时,我查看了它,结果是服务器发送了一组TCP RST标志

最后一点信息是,如果在下载后很快单击另一个链接,它会工作,但在后续操作中仍然会这样做,这让我相信某些异步操作最终会导致连接重置

如果有任何帮助,我将不胜感激,我已经为此绞尽脑汁一个星期了。下面是我的代码,StorageItem是我的web主机(Rackspace)中的一个类,文件存储在云中:

public void ViewFile(string containerName, string FileName, string clientFileName, string extension)
{
    StorageItem fileItem = conn.GetStorageItem(containerName, FileName);

    int readLength = 2097152;
    long fileLength = fileItem.FileLength;
    int numIterations = Convert.ToInt32(fileLength / Convert.ToInt32(readLength)) + 1;


    HttpResponse Response = HttpContext.Current.Response;

    Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}{1}", clientFileName, extension));
    Response.AddHeader("Content-Length", fileItem.FileLength.ToString());
    Response.ContentType = fileItem.ContentType;

    byte[] imageBytes = new byte[readLength];
    Stream inputStream = fileItem.ObjectStream;
    int i = 0;
    Response.Flush();
    for (i = 0; i < numIterations; i++)
    {
        long curPosition = fileItem.ObjectStream.Position;
        if (curPosition + readLength > fileLength)
            readLength = Convert.ToInt32(fileLength - curPosition);
        inputStream.Read(imageBytes, 0, readLength);
        Response.BinaryWrite(imageBytes);
        if (numIterations + 1 % 30 == 0)
            inputStream.Flush();
    }
    inputStream.Close();
    fileItem.ObjectStream.Close();
    Response.End();

}
public void ViewFile(字符串containerName、字符串文件名、字符串clientFileName、字符串扩展名)
{
StorageItem fileItem=conn.GetStorageItem(containerName,文件名);
int readLength=2097152;
long fileLength=fileItem.fileLength;
int numIterations=Convert.ToInt32(fileLength/Convert.ToInt32(readLength))+1;
HttpResponse Response=HttpContext.Current.Response;
AddHeader(“内容处置”,String.Format(“附件;文件名={0}{1}”,clientFileName,扩展名));
AddHeader(“Content-Length”,fileItem.FileLength.ToString());
Response.ContentType=fileItem.ContentType;
字节[]图像字节=新字节[readLength];
Stream inputStream=fileItem.ObjectStream;
int i=0;
Response.Flush();
对于(i=0;ifileLength)
readLength=Convert.ToInt32(fileLength-curPosition);
读取(imageBytes,0,readLength);
响应。二进制写入(imageBytes);
如果(数量+1%30==0)
inputStream.Flush();
}
inputStream.Close();
fileItem.ObjectStream.Close();
Response.End();
}

我想我已经解决了这个问题。通过Fiddler查看请求,它抱怨服务器报告的内容长度与实际传输之间存在差异。Fiddler在运行时会自动更正此问题,当我让Fiddler运行时,问题就消失了。我通过添加连接、保持活动标题永久解决了这个问题。