知识大全 Response.WriteFile无法下载大文件
Posted 文件
篇首语:识字粗堪供赋役,不须辛苦慕公卿。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Response.WriteFile无法下载大文件相关的知识,希望对你有一定的参考价值。
Response.WriteFile无法下载大文件 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
当您尝试使用 response writefile 方法下载大文件时 下载操作可能没有响应 并且随后可能会收到以下错误信息之一 The page cannot be displayed 或 Server Application UnavailableThe Web application you are attempting to access on this Web server is currently unavailable Please hit the Refresh button in your Web browser to retry your request Administrator Note:An error message detailing the cause of this specific request failure can be found in the system event log of the web server Please review this log entry to discover what caused this error to occur 您还可能会在应用程序事件日志中看到以下消息Aspnet_wp exe(对于在 Microsoft Internet 信息服务 [IIS] 上运行的应用程序 则为 W wp exe)意外停止
在此过程中 您还可能会发现 Web 服务器的内存使用量增加 回到顶端原因
Web 服务器计算机的硬件配置决定您可以成功下载的最大文件大小 当 ASP NET 辅助进程(Aspnet_wp exe 对于在 Internet 信息服务 [IIS] 上运行的应用程序 则为 W wp exe)执行文件下载请求时 会出现文件下载对话框 ASP NET 辅助进程开始向 Microsoft Internet 信息服务进程(Inetinfo exe 或 Dllhost exe)发送数据 它不等您单击 确定 即开始发送 根据计算机的配置 IIS 进程可能会处理数据 也可能会将数据缓存在内存中 如果文件太大 在这两个进程相互通信的过程中 数据将被缓存在内存中 这可能会导致服务器上的内存使用量增加 出现此错误的原因是 Web 服务器上的内存限制 回到顶端替代方法
要解决此问题 请使用以下任一方法 将数据分成较小的部分 然后将其移动到输出流以供下载 从而获取这些数据 以下代码演示了如何完成此操作 重要说明 当您在 ASP NET 应用程序的 nfig 文件中将编译元素的 debug 属性值设置为 false 时 必须针对要下载的文件大小将 server scripttimeout 属性设置为适当的值 默认情况下 server scripttimeout 值被设置为 秒 但是 当 debug 属性被设置为 true 时 server scripttimeout 值将被设置为一个非常大的值( 秒) 作为一名开发人员 您必须知道这可能会对您的 ASP NET Web 应用程序的行为造成的影响 此外 在下面的代码中 您还必须知道与 filestream 构造函数一起使用的参数值 指定的枚举值会对提供的功能产生重大影响 有关更多信息 请参考 参考 一节中的 filestream 链接 visual Basic NET 代码Dim iStream As System IO Stream Buffer to read K bytes in chunk: Dim buffer( ) As Byte Length of the file: Dim length As Integer Total bytes to read: Dim dataToRead As Long Identify the file to download including its path Dim filepath As String = DownloadFileName Identify the file name Dim filename As String = System IO Path GetFileName(filepath) Try Open the file iStream = New System IO FileStream(filepath System IO FileMode Open _ IO FileAccess Read IO FileShare Read) Total bytes to read: dataToRead = iStream Length Response ContentType = application/octet stream Response AddHeader( Content Disposition attachment; filename= & filename) Read the bytes While dataToRead > Verify that the client is connected If Response IsClientConnected Then Read the data in buffer length = iStream Read(buffer ) Write the data to the current output stream Response OutputStream Write(buffer length) Flush the data to the HTML output Response Flush() ReDim buffer( ) Clear the buffer dataToRead = dataToRead length Else prevent infinite loop if user disconnects dataToRead = End If End While Catch ex As Exception Trap the error if any Response Write( Error : & ex Message) Finally If IsNothing(iStream) = False Then Close the file iStream Close() End If End Try
Visual C# NET 代码System IO Stream iStream = null; // Buffer to read K bytes in chunk: byte[] buffer = new Byte[ ]; // Length of the file: int length; // Total bytes to read: long dataToRead; // Identify the file to download including its path string filepath = DownloadFileName ; // Identify the file name string filename = System IO Path GetFileName(filepath); try // Open the file iStream = new System IO FileStream(filepath System IO FileMode Open System IO FileAccess Read System IO FileShare Read); // Total bytes to read: dataToRead = iStream Length; Response ContentType = application/octet stream ; Response AddHeader( Content Disposition attachment; filename= + filename); // Read the bytes while (dataToRead > ) // Verify that the client is connected if (Response IsClientConnected) // Read the data in buffer length = iStream Read(buffer ); // Write the data to the current output stream Response OutputStream Write(buffer length); // Flush the data to the HTML output Response Flush(); buffer= new Byte[ ]; dataToRead = dataToRead length; else //prevent infinite loop if user disconnects dataToRead = ; catch (Exception ex) // Trap the error if any Response Write( Error : + ex Message); finally if (iStream != null) //Close the file iStream Close();
将 DownloadFileName 替换为大于 MB 的文件的名称 或 &# ; 为用户提供用于下载文件的链接 或 &# ; 使用 Microsoft ASP 进行下载或者与 ASP 一起使用 Sofare Artisans FileUp 或 &# ; 创建 ISAPI 扩展以下载文件 或 &# ; 使用 FTP 下载文件 回到顶端状态
这种现象是设计导致的 回到顶端更多信息
重现此问题的步骤
在 Microsoft Visual Basic NET 或 Microsoft Visual C# NET 中 新建一个 Web 应用程序项目 默认情况下 将创建 WebForm aspx 将一个按钮对象从工具箱拖到 WebForm aspx 双击该按钮对象以便在代码视图中打开 click 事件 将以下代码粘贴到 Button click 事件中 visual Basic NET 代码Identify the file to download including its path Dim filepath As String = DownloadFileName Identify the file name Dim filename As String = System IO Path GetFileName(filepath) Response Clear() Specify the Type of the downloadable file Response ContentType = application/octet stream Set the Default file name in the FileDownload dialog box Response AddHeader( Content Disposition attachment; filename= & filename & ) Response Flush() Download the file Response WriteFile(filepath)
Visual C# NET 代码 将 DownloadFileName 替换为大于 MB 的文件的名称 在 调试 菜单上 单击 开始 单击 Button cha138/Article/program/net/201311/13320相关参考
知识大全 下载的软件无法运行,显示WINDOWS无法打开此文件。
下载的软件无法运行,显示WINDOWS无法打开此文件。 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧
手机苹果6突然无法下载王者荣耀,苹果6为什么无法下载“王者荣耀”?一般是以下几个原因将手机连线到电脑开启找到.android_secure资料夹,找到smdl2tmp1.asec档案,或者是其它名称,
知识大全 蓝魔i10s 安卓系统 装上百度云无法正常使用。就是不能从云端下载我之前上传的东西,下载速度总是零
蓝魔i10s安卓系统装上百度云无法正常使用。就是不能从云端下载我之前上传的东西,下载速度总是零你好,这是手机系统优化的问题,你只能等官方出更新包。win8系统无法正常使用百度云下载东西兼容性的原因还有
知识大全 我的百度知道有很多财富值,但下载百度文库的文档时又说财富值不足,无法兑换下载券。怎么回事啊,在线等
我的百度知道有很多财富值,但下载百度文库的文档时又说财富值不足,无法兑换下载券。怎么回事啊,在线等知道和文库的财富值不通用百度知道财富值不能兑换百度文库的下载券么?不可以的,知道和文库是不一样的。不过
知识大全 电脑上有些下载未完成的文件无法删除怎么办,有什么办法能删掉
电脑上有些下载未完成的文件无法删除怎么办,有什么办法能删掉通常有以下三种方法:1、首先关闭掉下载这些文件所使用的软件,然后再尝试删除,一般就可以直接删除掉。2、使用文件粉碎器等工具进行删除,可以强制删
知识大全 我的手机是诺基亚6120c,下载了东西为什说无法安装
我的手机是诺基亚6120c,下载了东西为什说无法安装?正常情况……6120c只能安装jar/jad/sis/sisx几种。有没有提示其他信息?就说无法安装?如果提示证书错误的,需要手机个人证书才行。如
知识大全 手机浏览器打开百度网盘分享链接,无法点击高速下载或者按保存到网盘都没反应,是怎么了
手机浏览器打开百度网盘分享链接,无法点击高速下载或者按保存到网盘都没反应,是怎么了这样的情况个人建议在手机上安装百度网盘,登录后,再点击就可以打开网盘下载。手机百度网盘无法用,点高速下载和保存到网盘都
知识大全 买了苹果4代手机后发现不好用,因为手机没有越狱,无法自由下载歌曲和电影游戏等,就连游戏都购买不了
买了苹果4代手机后发现不好用,因为手机没有越狱,无法自由下载歌曲和电影游戏等,就连游戏都购买不了!未越狱,打不开装破解版软件的权限,但是你可以去appstore里面下载一些免费版本的正版软件至于下载音
知识大全 我播放器下载过来了!但是有省略号歌曲将无法正常播放怎么弄的啊!急救
QQ空间音乐怎么加的啊!我播放器下载过来了!但是有省略号歌曲将无法正常播放怎么弄的啊!急救! 以下文字资料是由(历史新知网www.cha138.com)小编为大家搜集整理后发布的
知识大全 三星GT-I8558手机所下载的软件都无法安装到SD卡,SD卡还有7G都剩余空间
三星GT-I8558手机所下载的软件都无法安装到SD卡,SD卡还有7G都剩余空间 以下文字资料是由(本站网www.cha138.com)小编为大家搜集整理后发布的内容,