下载最大文件大小限制的.zip文件 [英] downloading .zip file with maximum file size limit
问题描述
我在开发asp.net项目,C#2010年。我试图下载.zip格式的MP3文件。它可以在本地PC精细即使尺寸为80到150 MB之间。它也可以活的服务器上,而.zip文件的大小是 10至20 MB
,但现在我已经上载是 80到150 MB之间的文件
,它不工作,而不是只给出页面加载任何错误。页面加载可能是因为我已在设定的最大超时的web.config
文件。
I am developing project in asp.net, c# 2010. In that i am trying to download mp3 files in .zip format. It works fine in local PC even if size is between 80 to 150 MB. It also works on live server while .zip file size is between 10 to 20 MB
but now i have uploaded files that are between 80 to 150 MB
and It not works and not gives any error only loading page. Page is loading may be because i have set maximum timeout in web.config
file.
下载code
if (File.Exists(virtualPath))
{
FileInfo file = new FileInfo(virtualPath);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(AlbumName) + "\"");
Response.AppendHeader("content-length", file.Length.ToString());
Response.WriteFile(virtualPath);
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
的Web.config
<system.web>
<customErrors mode="Off"></customErrors>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2000000000" executionTimeout="999999"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2000000000" />
</requestFiltering>
</security>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
不知道是什么原因。请帮我解决这个错误。如果你有其它的选择,这将是巨大的。
Don't know what's the reason. Please help me to solve this error. If you have alternate solutions it would be great.
修改
if (File.Exists(virtualPath))
{
FileInfo file = new FileInfo(virtualPath);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(AlbumName) + "\"");
Response.AppendHeader("content-length", file.Length.ToString());
Response.Buffer = false;
Response.TransmitFile(virtualPath);
//Response.WriteFile(virtualPath);
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
感谢
推荐答案
如果您使用 Response.TransmitFile(使用Server.Mappath(virtualpath))
,它会关闭缓冲你不必写入到输出流。
If you use Response.TransmitFile(Server.MapPath(virtualpath))
, it will turn buffering off and you don't have to write to the output stream.
这篇关于下载最大文件大小限制的.zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!