ASP.NET InputStream is not a stream

Discussion in 'ASP .Net' started by Steve Drake, Oct 13, 2004.

  1. Steve Drake

    Steve Drake Guest

    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
    Steve Drake, Oct 13, 2004
    #1
    1. Advertising

  2. Steve Drake

    bruce barker Guest

    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" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    news:%23FjT%...
    > 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
    >
    >
    bruce barker, Oct 13, 2004
    #2
    1. Advertising

  3. "Steve Drake" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    news:%23FjT%...
    > 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.
    --

    -----
    John Saunders
    John Saunders, Oct 13, 2004
    #3
  4. Steve Drake

    Steve Drake Guest

    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" <> wrote in message
    news:#...
    > 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" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    > news:%23FjT%...
    > > 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
    > >
    > >

    >
    >
    Steve Drake, Oct 14, 2004
    #4
  5. Steve Drake

    Steve Drake Guest

    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
    }
    }
    Steve Drake, Oct 14, 2004
    #5
  6. Steve Drake

    Steve Drake Guest

    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" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    news:#FjT#...
    > 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
    >
    >
    Steve Drake, Oct 14, 2004
    #6
  7. "Steve Drake" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    news:...
    >I get the same problem.


    Steve, what happens if your BeginProcessRequest method just does a
    inputStream.BeginRead(...)?
    --

    -----
    John Saunders
    John Saunders, Oct 14, 2004
    #7
  8. Steve Drake

    Gabe Garza Guest

    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" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    news:%...
    > 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" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
    > news:#FjT#...
    > > 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
    > >
    > >

    >
    >
    Gabe Garza, Oct 18, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henning Moll

    InputStream.read does not return

    Henning Moll, Nov 10, 2003, in forum: Java
    Replies:
    1
    Views:
    463
    Henning Moll
    Nov 10, 2003
  2. R
    Replies:
    5
    Views:
    2,113
    Kevin McMurtrie
    Mar 13, 2005
  3. Rasmusson, Lars
    Replies:
    1
    Views:
    754
    popov
    Apr 30, 2004
  4. Replies:
    9
    Views:
    627
    Alex Buell
    Apr 27, 2006
  5. OtisUsenet
    Replies:
    0
    Views:
    729
    OtisUsenet
    Sep 6, 2007
Loading...

Share This Page