我正在开发asp.net,c#2010中的项目。在那篇文章中,我尝试以.zip格式下载mp3文件。即使尺寸在80到150 MB之间,它在本地PC上也能正常工作。它也适用于直播服务器,而.zip文件大小介于10 to 20 MB
之间,但现在我已经上传了80 to 150 MB
之间的文件,它无法正常工作,并且不会提供任何只载入页面的错误。正在加载页面可能是因为我在web.config
文件中设置了最大超时时间。下载带有最大文件大小限制的.zip文件
下载代码
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>
不知道是什么原因。请帮我解决这个错误。如果你有替代解决方案,那将会很棒。
编辑
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();
}
感谢
是否有IIS相关的错误?查看事件查看器。 – dcaswell
可能是它的IIS相关的错误,但我不知道。我怎样才能使用事件查看器? –
从开始菜单:事件查看器 – dcaswell