Large file download code found running on IIS.
But it stops at Azure AppService.
The file will download well and then stop when it reaches 1 GB.
Is there a problem with Azure App Service settings?
Please let me know what the problem is.
This is the ashx file code.
public void ProcessRequest(HttpContext context)
{
Stream stream = null;
int bytesToRead = 10000;
byte[] buffer = new Byte[bytesToRead];
string Url = context.Request.QueryString["Url"];
string FileName = HttpUtility.UrlEncode(context.Request.QueryString["FileName"]).Replace("+","%20");
try
{
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(Url);
HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
if (fileReq.ContentLength > 0)
fileResp.ContentLength = fileReq.ContentLength;
stream = fileResp.GetResponseStream();
var resp = HttpContext.Current.Response;
resp.ContentType = "application/octet-stream";
resp.AddHeader("Content-Disposition", "attachment; filename=\"" + FileName + "\"");
resp.AddHeader("Content-Length", fileResp.ContentLength.ToString());
int length;
do
{
if (resp.IsClientConnected)
{
length = stream.Read(buffer, 0, bytesToRead);
resp.OutputStream.Write(buffer, 0, length);
resp.Flush();
buffer = new Byte[bytesToRead];
}
else
{
// cancel the download if client has disconnected
length = -1;
}
} while (length > 0); //Repeat until no data is read
}
finally
{
if (stream != null)
{
//Close the input stream
stream.Close();
}
}
}