tags:

views:

345

answers:

3

I get the following error when trying to use Response.Redirect in one of my ASP.NET pages:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: offset]
   System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count) +8858392
   System.Web.HttpResponseStreamFilterSink.Write(Byte[] buffer, Int32 offset, Int32 count) +30      
   System.Web.HttpWriter.Filter(Boolean finalFiltering) +8754611
   System.Web.HttpResponse.FilterOutput() +82
   System.Web.ApplicationStepManager.ResumeSteps(Exception error) +501
   System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +123
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +379

I've never seen this before. It is happening if I Response.Redirect during the Page Load event.

Any Ideas?

EDIT: It's not my code, This is happening if I were to just stick Response.Redirect by itself in Page_Load.

EDIT #2: Using a 302 FOUND header works fine, but isn't that what response.redirect is supposed to do anyways?

A: 

I would review the code of the destination page carefully (since you comment the error is happening there). It is probably using something that depends on the request. I have never seen a similar error, but it really looks like you should be focusing on any special stuff that page is doing.

eglasius
It doesn't matter what the destination page is. I can point at any page on the site...it seems like its coming from the framework itself looking at the stack trace.
FlySwat
A: 

I don't know why your code is specifically doing this - but I had a complete failure of Response.Redirect in a similar way so in desperation I tried

Response.Redirect(url, false)

and the code magically started to work. I have no idea why it worked but work it did and the code is currently living happily in production somewhere. I appreciate randomly trying stuff until it works isn't exactly recommended in Comp Sci course - but desperate times etc...

Tim Brown
+1  A: 

This probably won't help much, but the exception itself is thrown inside HttpResponseStream.Write(byte[] buffer, int offset, int count), when either offset < 0 (which it isn't) or buffer length is zero. From what I understand, this could happen if buffered output is enabled and something managed to write a zero bytes into a stream.

I would try calling a Flush before doing the redirect and experiment with the second parameter. I would also check the web.config for any custom filter registration (unlikely though). Also make sure that your target application does not have asynchronous page processing, which could cause a havoc.

Apparently other people have been getting similar error, but usually when writing their own filters. I would end up debugging on the assembler level...

Ruslan