C# IIS7缓冲区大小限制
我的问题发生在尝试通过http请求下载视频文件时 在以下使用IIS7的操作系统中: win2008 32位,win2008 R2 64位 目前工作正常:win2003,vista64(IIS6) 问题描述: 当用户通过C请求大于256mb的文件时,即使在 使用Content-Length参数,文件似乎大小合适,但不是完整的 内容 当请求文件的URL时,我得到了完整的文件,问题只通过 C#脚本,也是将完整缓冲区发送给用户的C#响应 我在文章中更改了IIS7设置: 但它仍然不起作用 此外,任何地方都没有评论或错误 请查找我的代码示例:C# IIS7缓冲区大小限制,c#,iis-7,size,buffer,limit,C#,Iis 7,Size,Buffer,Limit,我的问题发生在尝试通过http请求下载视频文件时 在以下使用IIS7的操作系统中: win2008 32位,win2008 R2 64位 目前工作正常:win2003,vista64(IIS6) 问题描述: 当用户通过C请求大于256mb的文件时,即使在 使用Content-Length参数,文件似乎大小合适,但不是完整的 内容 当请求文件的URL时,我得到了完整的文件,问题只通过 C#脚本,也是将完整缓冲区发送给用户的C#响应 我在文章中更改了IIS7设置: 但它仍然不起作用 此外,任何地方
var context = System.Web.HttpContext.Current;
context.Response.ContentEncoding = Encoding.GetEncoding("windows-1255");
context.Response.HeaderEncoding = Encoding.GetEncoding("UTF-8");
context.Response.Charset = "utf-8";
System.IO.Stream iStream = null;
// Buffer to read 100K bytes in chunk:
byte[] buffer = new Byte[100000];
// Length of the file:
int length=0;
// Total bytes to read:
long dataToRead=0;
// Identify the file to download including its path.
string filepath = u.Trim(BigFile);
// Identify the file name.
string filename = System.IO.Path.GetFileName(filepath);
Start.Value = u.Time();
try
{
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
dataToRead = iStream.Length;
context.Response.Charset = "";
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
context.Response.AddHeader("Content-Length", dataToRead.ToString());
while (dataToRead > 0)
{
if (context.Response.IsClientConnected)
{
length = iStream.Read(buffer, 0, 100000);
context.Response.OutputStream.Write(buffer, 0, length);
context.Response.Flush();
buffer = new Byte[100000];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception ex)
{
context.Response.Write("Error : " + ex.Message);
}
finally
{
if (iStream != null)
{
iStream.Close();
}
context.Response.Close();
}
我要感谢你的帮助。
谢谢。您是否尝试添加
context.Response.BufferOutput=false代码>到您的代码?我只是尝试了一下-它没有做任何更改:(