Erick
Erick

Reputation: 6089

How to control max response size

I have a web application I support that have sometimes huge web pages to render.

Sometimes I have this exception (it is not linked to an upload the user make, the webpage render about 22MB of Html):

Error Caught in Page : http://example.com/thepage.aspx
Error Message:Maximum request length exceeded.
Stack Trace:   at System.Web.HttpRequest.GetEntireRawContent()
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.get_Form()
   at System.Web.HttpRequest.get_HasForm()
   at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
   at System.Web.UI.Page.DeterminePostBackMode()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

I tried to use maxRequestLength property of HttpRuntime node in web.config but it doesn't seem to control that.

As test case I tried to set it to 5K but the webpage shows even if it's bigger (it's around 150K) so I guess it will not permit to show huge webpages.

Is there a way I can control maximum response size and avoid the "Maximum request length exceeded" error ?

If it changes anything we are using .Net 4.0 with IIS 6.0

Upvotes: 0

Views: 3827

Answers (1)

Aristos
Aristos

Reputation: 66641

Set Response.Buffer=false for that page, and use the Response.Flush() time to time as you render your page.

This way you can avoid to render all data at ones to the buffer and wait this buffer to full before send it.

Also disable the viewstate on the controls that you do not needed.

If the above can not solve the issue then you need to redesign your page using a different type of control that allow them and you can send data to the browser time to time using the fluah(). A repeater control can work, maybe a gridview may not work.

Upvotes: 1

Related Questions