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
Getting All File Names from a Folder Using C#
What Is the Purpose of Anonymous { } Blocks in C Style Languages
Minifying and Combining Files in .Net
Good Resource to Learn Bdd, Tdd (Ruby , C#, JavaScript)
Does Java Have Something Like C#'s Ref and Out Keywords
How to Work with Time Zones in ASP.NET
What Is the Connection String for Localdb for Version 11
Standardoutput.Readtoend() Hangs
Linq - Left Join on Multiple (Or) Conditions
How to Upload Files in ASP.NET Core
Query an Xdocument for Elements by Name at Any Depth
How to Get Memcached Running on a Windows (X64) 64Bit Environment
How to Display Formatted Code in Webpage
Upload File Through C# Using JSON Request and Restsharp
Webexception How to Get Whole Response with a Body
How to Use .Net Reflection to Check for Nullable Reference Type