Modify MaxFieldLength and MaxRequestBytes to completely resolve request Too long problem _win Server

Source: Internet
Author: User
Tags documentation


When iis7/7.5 receives a request header that is longer than 16K (the default), a bad request-request Too Long is raised. HTTP Error 400. The size of the request headers is too long. of errors.



Blog Park server has encountered this problem, I wrote a blog post (CNZZ statistical code caused by bad request-request Too Long), the problem is due to the Third-party statistical services CNZZ Statistical code written to a large number of cookies, The request carries these cookies, causing the request header length to exceed the limit.



Originally thought this problem only appears in the Chrome, later has the park friend feedback Firefox also can appear this question. So, to solve this problem, you have to start with the server, and this article is about how to do it from the server side.



Where to begin



According to the IIS Official forum post (HTTP 400. The size of the request headers is too long), the 16K header/Request length limit is the registry (hkey_local_machine\system\currentcontrolset\services\ Http\parameters) is determined by the two parameters MaxFieldLength (Request headers) and MaxRequestBytes (the request header and the request body). So, to start with these two parameters.



Understand the target.



Learn more about MaxRequestBytes and maxfieldlength through Microsoft's official documentation (HTTP://SUPPORT.MICROSOFT.COM/KB/820129):



MaxFieldLength- Sets a upper limit for each header.



Use 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.



Use to set the maximum total number of bytes (default 16K) for the request line (request body) and the request header.



How to strike


The target is to adjust the value of MaxFieldLength and MaxRequestBytes (this assumes that the two values are modified to 32K) and make it effective.



Running regedit, entering Hkey_local_machine\system\currentcontrolset\services\http\parameters,



1. Add the item of type DWORD (32-bit), named MaxFieldLength, value is decimal 32768;
2. Add an item of type DWORD (32-bit), named MaxRequestBytes, with a value of decimal 32768.



Add well, how do you get them into effect? The easiest way is to reboot, but for the server, the last thing you want to do is reboot.

Fortunately, Microsoft's official documentation mentions a solution that does not restart, requiring four commands to be run:


code as follows:

NET stop http
NET start HTTP
net stop iisadmin/y
net start ServiceName


However, the 3rd command net stop iisadmin all IIS-related services, and the 4th command launches all IIS-related services one by one.
Although there is no need to reboot the server, the solution for these four commands I don't like ... There is no better solution on the internet ...
Later, by groping, a simpler approach was found, with just three commands:

code as follows:

NET stop http
NET start HTTP
IISReset


This method has been validated on the server by actual validation.

Summary

One of the pleasures of technology is being able to find the solution that you want in your mind when you encounter a problem, not the solution you want to have in your heart, but when it comes out, you will know it-that's it!
The same is true in life, the person in your mind that you can't accurately describe, and when she or he appears, you will know-that's him/him.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.