I'm getting the following response from SharePoint search after submitting a long (> 2000 chars) queryString.

The length of the query string for this request exceeds the configured maxQueryStringLength value.

The response has code 400.

How do I change this value?

I have tried adding maxQueryStringLength="4096" to every web.config file known to man, but that does not seem to work.

Should I be making this change elsewhere?

This is the stack trace I find:

Exception information: Exception type: HttpException Exception message: The length of the query string for this request exceeds the configured maxQueryStringLength value. at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)

So what Config does ValidateInputIfRequiredByConfig refer to? I take it this may be something SharePoint specific?

  • Have you checked this and this? – Ganesh Sanap Dec 14 '18 at 9:36
  • No, I have mainly looked at relevant information. To re-iterate: I have updated web.config to 4096 everywhere. I have also updated the values in IIS itself. I haven't the faintest what MicroStrategy is. – Christofer Ohlsson Dec 14 '18 at 9:44
  • How is it possible that nobody actually knows this? This should be so very basic for SharePoint knowledgeable people? – Christofer Ohlsson Dec 27 '18 at 13:28

It appears "ValidateInputIfRequiredByConfig" is a method in the .net framework. You can view the implementation of this method at https://referencesource.microsoft.com/#system.web/HttpRequest.cs,3ed0fe4075d2649a

It refers to the httpRuntime section in the web.config and updating web.config as below should possibly resolve the issue.

    <httpRuntime maxUrlLength="10999" maxQueryStringLength="4096" />

        <requestLimits maxUrl="10999" maxQueryString="4096" />

Implimentation of "ValidateInputIfRequiredByConfig":

internal void ValidateInputIfRequiredByConfig() {
        // Do we need to enable request validation?
        RuntimeConfig config = RuntimeConfig.GetConfig(Context);
        HttpRuntimeSection runtimeSection = config.HttpRuntime;

        // Perform Path & QueryString validation checks for non-state_server requests
        if (CanValidateRequest()) {
            string requestUrl = Path;

            // Verify the URL & QS lengths
            if (requestUrl.Length > runtimeSection.MaxUrlLength) {
                throw new HttpException(400, SR.GetString(SR.Url_too_long));
            if (QueryStringText.Length > runtimeSection.MaxQueryStringLength) {
                throw new HttpException(400, SR.GetString(SR.QueryString_too_long));

            // Verify that the URL does not contain invalid chars
            char [] invalidChars = runtimeSection.RequestPathInvalidCharactersArray;
            if (invalidChars != null && invalidChars.Length > 0) {
                int index = requestUrl.IndexOfAny(invalidChars);
                if (index >= 0) {
                    string invalidString = new string(requestUrl[index], 1);
                    throw new HttpException(400, SR.GetString(SR.Dangerous_input_detected,
                                                              "Request.Path", invalidString));

        // only enable request validation for the entire pipeline in v4.0+ of the framework
        Version requestValidationMode = runtimeSection.RequestValidationMode;
        if (requestValidationMode == VersionUtil.Framework00) {
            // DevDiv #412689: <httpRuntime requestValidationMode="0.0" /> should suppress validation for
            // the entire request, even if a call to ValidateInput() takes place. The request path
            // characters and cookieless header (see 'needToValidateCookielessHeader') are still validated
            // if necessary. These can be suppressed via <httpRuntime requestPathInvalidChars="" />.
            _flags[requestValidationSuppressed] = true;
        else if (requestValidationMode >= VersionUtil.Framework40) {

            // Mode v4.5+ implies granular request validation
            if (requestValidationMode >= VersionUtil.Framework45) {

Edited: Please refer this link

The length limit of a KQL query varies depending on how you create it. If you create the KQL query by using the default SharePoint search front end, the length limit is 2,048 characters. However, KQL queries you create programmatically by using the Query object model have a default length limit of 4,096 characters. You can increase this limit up to 20,480 characters by using the MaxKeywordQueryTextLength property or the DiscoveryMaxKeywordQueryTextLength property (for eDiscovery).

Related PowerShell commands:

#Get all Service applications
Get-SPServiceApplication | Select DisplayName

#Get Search Service Application using the Display Name
$search = Get-SPServiceApplication | where {$_.displayname -contains "SearchServiceName"}
#Display MaxKeywordQueryTextLength
#Display DiscoveryMaxKeywordQueryTextLength

#Update MaxKeywordQueryTextLength
$search.MaxKeywordQueryTextLength = NewValue

## May not be needed but to ensure everything is intact 
Restart-Service spsearchhostcontroller
  • Thank you for this link to the implementation. However, I had already updated the httpRuntime section of my web.config file(s), without success. The error still persists. – Christofer Ohlsson Dec 20 '18 at 10:02
  • Is this out of the box SharePoint search? What is the URL of the search result page? Is it "/_layouts/15/osssearchresults.aspx" or a custom page? – Prasanna Dec 20 '18 at 23:44
  • The URL is /_api/search/query – Christofer Ohlsson Dec 21 '18 at 14:16
  • take a look on social.technet.microsoft.com/Forums/en-US/… – Prasanna Dec 21 '18 at 17:58
  • The way I understand that link @Prasanna (you did not specify what in that link I would find useful) is I can not get past 2,048 characters if the query is not being created programatically. Is this correct? – Christofer Ohlsson Dec 27 '18 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.