It would have been animated if the image upload at Blogger wasn't screwed! ~x(Yesterday I was trying desperately to understand why my web site was crashing without any error, the only information I could get being that the connection to the server has been reset. I've spent hours trying to determine what was wrong. Apparently I needed a break, because today it took me a few minutes to realize what it was.

First of all, duh! If there are issues with the connection server, look into the Windows Application Event Log. But we'll get there.

The "error" appeared at any postback after I loaded a certain page, but only if that page displayed a minimum of data. Above that threshold I would get the server reset thing that you can see both in IE7 and FireFox2 in the animated GIF. Basically the error messages were:
FireFox
The connection was reset
The connection to the server was reset while the page was loading.

Internet Explorer
Internet Explorer cannot display the webpage
Internet connectivity has been lost.
The website is temporarily unavailable.
The Domain Name Server (DNS) is not reachable.

Ajax UpdatePanel
Server returned error 12031

So, today I realised I should look in the Application Event Log and this Web Event Warning was displayed (shortened it a bit):
Event code: 3004
Event message: Post size exceeded allowed limits.

Process information:
Process name: aspnet_wp.exe

Exception information:
Exception type: HttpException
Exception 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)


It turns out I was putting a lot of data into the ViewState, which, as you know, is saved as a HiddenField (a.k.a. hidden html input) and the size of it exceeded the set up maximum POST size.

Solutions:
A. Add this code to your page: (NET 2.0)
 protected override PageStatePersister PageStatePersister
{
get
{
//return base.PageStatePersister;
return new SessionPageStatePersister(this);
}
}


This should put your ViewState into the Session, rather than in the page. This solves some other issues as well, obviously.

B. Increase the maximum Request limit (default is 4Mb)
- In the Machine.config file, change the maxRequestLength attribute of the <httpRuntime> configuration section to a larger value. This change affects the whole computer.
- In the Web.config file, override the value of maxRequestLength for the application. For example, the following entry in Web.config allows files that are less than or equal to 8 megabytes (MB) to be uploaded:
<httpRuntime maxRequestLength="8192" />

This is an exact quote from the Microsoft support page.

That's it, folks!

Update:

The maxRequestLength maximum value is 2097151, that is less than 2.1Gb. No file that exceeds this size can be uploaded through the default upload mechanism.

Comments

Anonymous

<p>Thanks for this post! It saved my day with bugs I can't figure out why and how it happened?</p>

Anonymous

Anonymous

Thanks for this post! It saved my day with bugs I can&#39;t figure out why and how it happened?

Anonymous

Ganesan Natarajan

<p>Hi,<br>I make the changes, but still am getting the same error...</p>

Ganesan Natarajan

Ganesan Natarajan

Hi,<br>I make the changes, but still am getting the same error...

Ganesan Natarajan

Allan Oliveira

<p>Thank you very much.<br><br>I think my problem was ajax <a href="http://asp.net" rel="nofollow noopener" title="asp.net">asp.net</a><br>but never imagine can be size of viewstate.<br><br></p>

Allan Oliveira

Allan Oliveira

Thank you very much.<br><br>I think my problem was ajax asp.net<br>but never imagine can be size of viewstate.<br><br>

Allan Oliveira

Siderite

<p>Thanks, Denil, for sharing the VB version of the code.</p>

Siderite

Denil Roy

<p>Vb Code:- <br><br> <br><br>WebConfig:<br><br> "&lt;<br>httpRuntime maxRequestLength="8192" /&gt;"</p>

Denil Roy

Denil Roy

<p>Vb Code:- <br><br>Code window : <br> Protected Overrides ReadOnly Property PageStatePersister() As PageStatePersister<br> Get<br> 'return base.PageStatePersister;<br> Return New SessionPageStatePersister(Me)<br> End Get<br> End Property<br><br>WebConfig:<br><br> <br></p>

Denil Roy

Denil Roy

Vb Code:- <br><br> <br><br>WebConfig:<br><br> &quot;&lt;<br>httpRuntime maxRequestLength=&quot;8192&quot; /&gt;&quot;

Denil Roy

Denil Roy

Vb Code:- <br><br>Code window : <br> Protected Overrides ReadOnly Property PageStatePersister() As PageStatePersister<br> Get<br> &#39;return base.PageStatePersister;<br> Return New SessionPageStatePersister(Me)<br> End Get<br> End Property<br><br>WebConfig:<br><br> <br>

Denil Roy

Anonymous

<p>Thanks a lot,<br> I had a simple string in the viewstate, but I was experiencing your same problem and, btw, I solved the problem usign your suggestion.<br><br>I suggest you (if you can) to add some keywords like "unknwon reason", "post back page", "link button".<br>Eventually I found your post with this query on Saint Google: ""The connection was reset" without any reason aspx postback"<br><br>cheers<br>stmod</p>

Anonymous

Anonymous

Thanks a lot,<br> I had a simple string in the viewstate, but I was experiencing your same problem and, btw, I solved the problem usign your suggestion.<br><br>I suggest you (if you can) to add some keywords like &quot;unknwon reason&quot;, &quot;post back page&quot;, &quot;link button&quot;.<br>Eventually I found your post with this query on Saint Google: &quot;&quot;The connection was reset&quot; without any reason aspx postback&quot;<br><br>cheers<br>stmod

Anonymous

Neilius

<p>Thanks. I didn't even know what a PageStatePersister was till I read this article. Problem solved. My pigs are now ready to fly :)</p>

Neilius

Neilius

Thanks. I didn&#39;t even know what a PageStatePersister was till I read this article. Problem solved. My pigs are now ready to fly :)

Neilius

rameezshaikh

<p>Tahnks a lot !<br>It helped me.<br><br>-Rameez Shaikh</p>

rameezshaikh

rameezshaikh

Tahnks a lot !<br>It helped me.<br><br>-Rameez Shaikh

rameezshaikh

Siderite

<p>As you can see in the documentation of the httpRuntime element (<a rel="nofollow">http://msdn.microsoft.com/en-us/library/e1f13641.aspx</a>), it is a tag that resides as a child tag of system.web. So something like this:<br>&lt;configuration&gt;<br> &lt;system.web&gt;<br> &lt;httpRuntime ...</p>

Siderite

Siderite

As you can see in the documentation of the httpRuntime element (<a rel="nofollow">http://msdn.microsoft.com/en-us/library/e1f13641.aspx</a>), it is a tag that resides as a child tag of system.web. So something like this:<br>&lt;configuration&gt;<br> &lt;system.web&gt;<br> &lt;httpRuntime ...

Siderite

Andrik McVean

<p>hello siderite.<br><br>this this very helpful but i can't find this tag in my web.config.<br><br>I am using <a href="http://vb.net" rel="nofollow noopener" title="vb.net">vb.net</a>..could you please help me. <br>if i need to paste it on web.config which section please?<br><br>really need your help.<br><br>thanks<br>andrik</p>

Andrik McVean

Andrik McVean

hello siderite.<br><br>this this very helpful but i can&#39;t find this tag in my web.config.<br><br>I am using vb.net..could you please help me. <br>if i need to paste it on web.config which section please?<br><br>really need your help.<br><br>thanks<br>andrik

Andrik McVean

Anonymous

<p>Thanks.. Rabbits were a chuckle too.</p>

Anonymous

lovedoughnut64

<p>Hi, like what u said and sounds like it will solve my issue. I'm not a programmer, can u do a step by step as i don't know what an event viewer is and it looks like i have to go into event viewer to configure the Firefox file. I have Firefox 3.6 and I'm getting the "The connection was reset" error. Thanks for any help.<br><br>LVDS</p>

lovedoughnut64

lovedoughnut64

<p>This comment has been removed by the author.</p>

lovedoughnut64

lovedoughnut64

Hi, like what u said and sounds like it will solve my issue. I&#39;m not a programmer, can u do a step by step as i don&#39;t know what an event viewer is and it looks like i have to go into event viewer to configure the Firefox file. I have Firefox 3.6 and I&#39;m getting the &quot;The connection was reset&quot; error. Thanks for any help.<br><br>LVDS

lovedoughnut64

lovedoughnut64

This comment has been removed by the author.

lovedoughnut64

aj

<p>This saved my bacon. I installed SQL Express 2008 and when I would get to a certain point in my web app, I'd get that "connection was reset" error. It only happened on POST operations. These attributes in web.config solved the problem. I'm ecstatic since I can now use the nice features of SQL 2008's manager alongside <a href="http://asp.net" rel="nofollow noopener" title="asp.net">asp.net</a> on my computer. Thanks!!</p>

aj

aj

This saved my bacon. I installed SQL Express 2008 and when I would get to a certain point in my web app, I&#39;d get that &quot;connection was reset&quot; error. It only happened on POST operations. These attributes in web.config solved the problem. I&#39;m ecstatic since I can now use the nice features of SQL 2008&#39;s manager alongside asp.net on my computer. Thanks!!

aj

Rodrigo Espinosa

<p>Thanks for you post, but my problem get resolved uninstalling nod32.<br><br>It had some problems dealing with proxies.</p>

Rodrigo Espinosa

Rodrigo Espinosa

Thanks for you post, but my problem get resolved uninstalling nod32.<br><br>It had some problems dealing with proxies.

Rodrigo Espinosa

Siderite

<p>The httpRuntime tag in web.config uses maxRequestLength for setting a maximum acceptable request length and executionTimeout to set a maximum acceptable execution time.<br><br>Check out this <a href="http://msdn.microsoft.com/en-us/library/e1f13641.aspx" rel="nofollow noopener" title="http://msdn.microsoft.com/en-us/library/e1f13641.aspx">httpRuntime Element</a></p>

Siderite

Siderite

The httpRuntime tag in web.config uses maxRequestLength for setting a maximum acceptable request length and executionTimeout to set a maximum acceptable execution time.<br><br>Check out this <a href="http://msdn.microsoft.com/en-us/library/e1f13641.aspx" rel="nofollow">httpRuntime Element</a>

Siderite

Hamza

<p>Siderite, nice post. Very helpful. Just wanted to check if my problem is related. I have an asynchronous request which gives me the same message if it takes a long time for the response. Ideally I would like the connection to live till the response is back rather than dropping dead. Have a look at the <a href="http://www.hamzaafaq.com/Sleep.aspx?sleeptime=10000" rel="nofollow noopener" title="http://www.hamzaafaq.com/Sleep.aspx?sleeptime=10000">test page</a> I've put up. If you change the sleeptime value to a bit higher (<a href="http://www.hamzaafaq.com/Sleep.aspx?sleeptime=40000" rel="nofollow noopener" title="http://www.hamzaafaq.com/Sleep.aspx?sleeptime=40000">example</a>), the connection just drops. Any solutions?</p>

Hamza

Hamza

Siderite, nice post. Very helpful. Just wanted to check if my problem is related. I have an asynchronous request which gives me the same message if it takes a long time for the response. Ideally I would like the connection to live till the response is back rather than dropping dead. Have a look at the <a href="http://www.hamzaafaq.com/Sleep.aspx?sleeptime=10000" rel="nofollow">test page</a> I&#39;ve put up. If you change the sleeptime value to a bit higher (<a href="http://www.hamzaafaq.com/Sleep.aspx?sleeptime=40000" rel="nofollow">example</a>), the connection just drops. Any solutions?

Hamza

slade73

<p>Thanks for posting this. The maxRequestLength was the fix I needed because I was allowing large files to be uploaded via a file input control.</p>

slade73

slade73

Thanks for posting this. The maxRequestLength was the fix I needed because I was allowing large files to be uploaded via a file input control.

slade73

the TaleCrafter

<p>Thank you very much. This one had me stumped. I had often wondered about that ViewState, and if it ever filled up.</p>

the TaleCrafter

Anonymous

Thank you very much. This one had me stumped. I had often wondered about that ViewState, and if it ever filled up.

Anonymous

Siderite

<p>You are most welcome! What queries did you use to search the web? Maybe I can add some of the words to the post so that people find it faster.</p>

Siderite

Siderite

You are most welcome! What queries did you use to search the web? Maybe I can add some of the words to the post so that people find it faster.

Siderite

Suresh

<p>This is Very Much Helpful Post (Error Code : 12031)after an 7Hrs of Search in Web atlast got this one.It Solved my Problem<br> Thanx a LOT "Siderite" <br><br>Regards<br>SURESH RAJ <br>MCST, MCPD</p>

Suresh

Suresh

This is Very Much Helpful Post (Error Code : 12031)after an 7Hrs of Search in Web atlast got this one.It Solved my Problem<br> Thanx a LOT &quot;Siderite&quot; <br><br>Regards<br>SURESH RAJ <br>MCST, MCPD

Suresh

Anonymous

<p>Siderite, Thanks too much for sharing your experience. It helped me a lot.</p>

Anonymous

Anonymous

Siderite, Thanks too much for sharing your experience. It helped me a lot.

Anonymous

Post a comment