zoukankan      html  css  js  c++  java
  • Downloading files from a server to client, using ASP.Net, when file size is too big for MemoryStream using Generic Handlers (ashx)

    Currently, I was trying to write an ASP.Net application that involved a user clicking a ASP.Net button control

    Once the control is clicked the back end stores the users information (first name, last name, email address, phone number, etc…) to a database. After that information is stored to a database, the system would then allow the user to download the file through an generic handler (.ashx file). The file size that was to be downloaded is 600MB.

    Once the database is updated, I call the DownloadFile.ashx generic handler. Upon execution of the generic handler I received the following “OutOfMemoryException” error

    OutOfMemoryException error

    This was a result from the following generic handler I was using

    This handler worked in the past, for very small files. The last time I was using this the file size was about 300MB. My friend @homeraguas reminded me that I might needed to check my web.config file to be sure that the following maxRequestLength and executionTimeout was set. It wasn’t in the web.config file. So I added the following

    Recompiled and published, then gave it another go. Still, I came across the “OutOfMemoryException” error. I looked around the net and came across this blog’s article utilizing the following method Reponse.TransmitFile();

    The HttpReponse.TransmitFile() method basically states it “Writes the specified file directly to an HTTP response output stream without buffering it in memory.”

    This makes sense to me, since the file I want to transfer is 600MB and I do not think the current server I am writing this web application for does not have adequate resources available. So the revision to the code I wrote/used is as follows

    The result was that it worked.

    ashx generic handler worked

    What do you guys think? Is this an adequate solution? Have a good one!

  • 相关阅读:
    python zip()函数转置表,操作列
    python 集合 无序非重 容器的操作
    前行
    工作读书放松: 做其他事情 1.运动(如焦),2.闭眼睡觉休息(如蔡),3.选择读其他书
    心在哪时间在哪路在哪
    vi全部替换
    选择
    知识 代码 算法
    code algorithm
    绕过CND查找真是IP地址
  • 原文地址:https://www.cnblogs.com/rainbowzc/p/3611925.html
Copyright © 2011-2022 走看看