Request Exceeds the Configured Maxquerystringlength When Using [Authorize]

request exceeds the configured maxQueryStringLength when using [Authorize]

When an unauthorized request comes in, the entire request is URL encoded, and added as a query string to the request to the authorization form, so I can see where this may result in a problem given your situation.

According to MSDN, the correct element to modify to reset maxQueryStringLength in web.config is the <httpRuntime> element inside the <system.web> element, see httpRuntime Element (ASP.NET Settings Schema). Try modifying that element.

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

Why don't you use TempData, it's meant to do stuff like this. So for example:

TempData["ErrorMessage"] = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";

Check this link.

EDIT

Pass your exception message like this:

TempData["Error"] = ex.Message();
TempData["ErrorMessage"] = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";

return RedirectToAction("Error", "Error");

Then just access it from your ErrorController, something like:

public ActionResult Error(string ex, string message)
{
var error = (string)TempData["Error"];
// do other magic ...
}

How to configure maxQueryStringLength in webapi?

I add this code into system.webServer section

<security>
<requestFiltering>
<requestLimits maxUrl="30000" maxQueryString="209007151" />
</requestFiltering>
</security>

and add

<httpRuntime maxUrlLength="10240" maxQueryStringLength="2097100"  targetFramework="4.5.2"/>

into system.web section and solved

How to configure the web.config to allow requests of any length

Add the following to your web.config:

<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="32768"/>
</requestFiltering>
</security>
</system.webServer>

See:

http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits

Updated to reflect comments.

requestLimits Element for requestFiltering [IIS Settings Schema]

You may have to add the following in your web.config as well

<system.web>
<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>
</system.web>

See: httpRuntime Element (ASP.NET Settings Schema)

Of course the numbers (32768 and 65536) in the config settings above are just examples. You don't have to use those exact values.



Related Topics



Leave a reply



Submit