IIS “Bad Request – Request Too Long. HTTP Error 400. The size of the request headers is too long.”

The size of The Request Headers is Too Long. If The length of The Request headers received in IIS7/7.5 exceeds 16K (The default value), an Error is raised.
I wrote a blog post about this problem (Bad Request-Request Too Long caused by statistics code of CNZZ). The reason for the problem is that the statistics code of third-party statistics service CNZZ writes a large number of cookies, which are carried when requested, resulting in the Request header length exceeding the limit.
I thought this was a problem only for Chrome, but then I got feedback from friends that it was also a problem for Firefox. So, to solve this problem, you have to start at the server end, and this article shares how to start at the server end.
where
According to The IIS forum post (HTTP 400. The size of The Request Headers is Too long), The 16K request header/request length limit is determined by two Parameters in the registry (HKEY_LOCAL_MACHINE\System\ Services\HTTP\Parameters) MaxFieldLength (request header) and MaxRequestBytes (request header and request body). So, you start with these two parameters.
Know your target
Through the Microsoft official documentation (http://support.microsoft.com/kb/820129) to learn more about MaxRequestBytes and MaxFieldLength:
MaxFieldLength – Sets an upper limit for each header.
Used to set the maximum number of bytes per request header (default 16K).
MaxRequestBytes – Determines the upper limit for the total size of the Request line and the headers.
Used to set the maximum total number of bytes between the request line (the body of the request) and the request header (16K by default).
How to start
Start by adjusting the values of MaxFieldLength and MaxRequestBytes (assuming 32K) to take effect.
Run regedit, go to HKEY_LOCAL_MACHINE\System\ Services\HTTP\Parameters,
1. Add an item of type DWORD(32-bit) with the name MaxFieldLength and the value decimal 32768;
2. Add items of type DWORD(32-bit), named MaxRequestBytes, value decimal 32768.

Ok, so how do we get them to work?The easiest thing to do is reboot, but the last thing you want to do with a server is reboot.
Fortunately, the solution to this problem is mentioned in the Official Microsoft documentation. You need to run four commands:

Net stop HTTP
net start HTTP
net stop iisadmin /y
net start servicename

But the third command, NET Stop iISadmin, will disable all services related to IIS, and the fourth command will start all services related to IIS one by one.
Although there is no need to restart the server, I don’t like the solution of these four commands… I couldn’t find a better solution on the Internet…
Then, by trial and error, I found an even simpler method that required only three commands:

net stop http
net start http
iisreset

This method has been validated in practice on the server.

Read More: