ASP.NET InputStream is not a stream

S

Steve Drake

All,

I have a HttpHandler that handles a PUT, if i PUT 700MEGs of data it runs
out of memory, i have found that this is due to the Request.InputStream
loading the entire stream when you access it.

If I run any of the following i get the error :

Context.Request.SaveAs(@"C:\1.xxx",false); // I get out of memory

System.Diagnostics.Trace.WriteLine(Context.Request.InputStream.CanRead); //
I get out of memory

byte[] data = new byte[4096];
data = Context.Request.BinaryRead(4096); // I get out of memory

Cheers

Steve
 
B

bruce barker

turn page buffering off.

Page.ResponseBufferOutput = false;

note: this will tie up an asp.net thread, and 2 communication threads until
completed. if you have many concurrent downloads you will quickly get a
server busy error.


-- bruce (sqlwork.com)
 
J

John Saunders

Steve Drake said:
All,

I have a HttpHandler that handles a PUT, if i PUT 700MEGs of data it runs
out of memory, i have found that this is due to the Request.InputStream
loading the entire stream when you access it.

Write an asynchronous handler.
 
S

Steve Drake

the request stream does not have the options of turning off this buffer.

but... i did try to see if it affected the request stream, and it still runs
out of memory.

Steve


bruce barker said:
turn page buffering off.

Page.ResponseBufferOutput = false;

note: this will tie up an asp.net thread, and 2 communication threads until
completed. if you have many concurrent downloads you will quickly get a
server busy error.


-- bruce (sqlwork.com)



Steve Drake said:
All,

I have a HttpHandler that handles a PUT, if i PUT 700MEGs of data it runs
out of memory, i have found that this is due to the Request.InputStream
loading the entire stream when you access it.

If I run any of the following i get the error :

Context.Request.SaveAs(@"C:\1.xxx",false); // I get out of memory

System.Diagnostics.Trace.WriteLine(Context.Request.InputStream.CanRead); //
I get out of memory

byte[] data = new byte[4096];
data = Context.Request.BinaryRead(4096); // I get out of memory

Cheers

Steve
 
S

Steve Drake

I get the same problem.

I have managed to reproduce this in a test app create a web project , call
it LargePUTTEST

I've done it with a async class but the real app is not. I don't think this
will matter.

Confgure IIS

Add VERB PUT to ASPX (Right click on APP in IIS, click configure, select
..ASPX, add put to list of verbs, eg change GET,HEAD,POST,DEBUG,OPTIONS to
GET,HEAD,POST,DEBUG,OPTIONS,PUT



Add this to the page load

private void Page_Load(object sender, System.EventArgs e)
{
System.IO.Stream RequestStream;
System.Net.HttpWebRequest Request =
(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://localhos
t/LargePUTTest/test.aspx");
Request.Method = "PUT";
Request.ContentLength = 1024 * 1024 * 1024;// 1 GIGish some people says
its 1024 * 1024 * 1000 :)
RequestStream = Request.GetRequestStream();
byte[] data = new byte[4096];
for(int i=0;i<Request.ContentLength;i+=4096)
RequestStream.Write(data,0,4096);
RequestStream.Close();
}

Add this file (name httpHandler.cs)

using System;
using System.Web;

namespace LargePUTTest
{
/// <summary>
/// Summary description for httpHandlers.
/// </summary>
public class httpHandler :IHttpAsyncHandler
{
public httpHandler()
{
//
// TODO: Add constructor logic here
//
}
#region IHttpAsyncHandler Members

public IAsyncResult BeginProcessRequest(HttpContext context,
System.AsyncCallback cb, object extraData)
{
// TODO: Add httpHandlers.BeginProcessRequest implementation
System.Diagnostics.Trace.WriteLine(context.Request.InputStream.CanRead);
// this causes the out of memory.
return null;
}

public void EndProcessRequest(IAsyncResult result)
{
// TODO: Add httpHandlers.EndProcessRequest implementation
}

#endregion

#region IHttpHandler Members

public void ProcessRequest(HttpContext context)
{
// TODO: Add httpHandlers.ProcessRequest implementation
}

public bool IsReusable
{
get
{
// TODO: Add httpHandlers.IsReusable getter implementation
return false;
}
}

#endregion
}
}
 
S

Steve Drake

I have logged this as a support call, and MS says that it copies the Request
stream into memory so you will get out of memory exceptions and there is now
way round it.

I consider this poor design.

Steve
 
G

Gabe Garza

Steve,

I'd write an ISAPI and either do a IO Completion using HSE_REQ_IO_COMPLETION
or just use EXTENSION_CONTROL_BLOCK *pEcb->ReadClient() to keep reading data
coming from the client until your 700 Meg file has been uploaded.

This will get you what you want, a stream.

Gabe

Steve Drake said:
I have logged this as a support call, and MS says that it copies the Request
stream into memory so you will get out of memory exceptions and there is now
way round it.

I consider this poor design.

Steve


Steve Drake said:
All,

I have a HttpHandler that handles a PUT, if i PUT 700MEGs of data it runs
out of memory, i have found that this is due to the Request.InputStream
loading the entire stream when you access it.

If I run any of the following i get the error :

Context.Request.SaveAs(@"C:\1.xxx",false); // I get out of memory

System.Diagnostics.Trace.WriteLine(Context.Request.InputStream.CanRead); //
I get out of memory

byte[] data = new byte[4096];
data = Context.Request.BinaryRead(4096); // I get out of memory

Cheers

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top