C# 此请求的查询字符串长度超过了配置的 maxQueryStringLength 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17590502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The length of the query string for this request exceeds the configured maxQueryStringLength value
提问by Pomster
I am trying to redirect to a view and keep getting the error posted in the question title.
我正在尝试重定向到视图并不断收到问题标题中发布的错误。
During breakpoint testing the code passing though the first bit of code iv lay down below setting the message and setting the exception. after continuing after the return redirect the very next page displayed is as follows.
在断点测试期间,通过代码 iv 的第一位传递的代码位于设置消息和设置异常的下方。返回重定向后继续后,显示的下一页如下。


Adding break points to the ErrorController and error model i found that the code never gets there.
向 ErrorController 和错误模型添加断点我发现代码永远不会到达那里。
The view i'm trying to post to is an error page. Here is so code to help you see the problem.
我试图发布的视图是一个错误页面。这里的代码可以帮助您查看问题。
The RedirectToAction:
RedirectToAction:
string message;
message = "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", new { ex = ex.ToString(), message = message});
The action in my ErrorController:
我的 ErrorController 中的操作:
public ActionResult Error(string ex, string message)
{
ViewBag.Message = "Error";
return View(new ErrorModel(ex, message));
}
My Error model:
我的错误模型:
namespace MvcResComm.Models
{
public class ErrorModel
{
public string ex { get; set; }
public string message { get; set; }
public ErrorModel(string ex, string message)
{
this.ex = ex;
this.message = message;
}
}
}
采纳答案by Dimitar Dimitrov
Why don't you use TempData, it's meant to do stuff like this. So for example:
你为什么不使用TempData,它的目的是做这样的事情。例如:
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:
然后只需从您的 访问它ErrorController,例如:
public ActionResult Error(string ex, string message)
{
var error = (string)TempData["Error"];
// do other magic ...
}
回答by David Colwell
There is a maxumum URL length value settable in the web.config file. This question has a similar problem ASP.NET MVC, Url Routing: Maximum Path (URL) Length
在 web.config 文件中有一个可设置的最大 URL 长度值。这个问题有一个类似的问题 ASP.NET MVC, Url Routing: Maximum Path (URL) Length
回答by Siraj Mansour
In you web.config
under the <system.web> <httpRuntime>tags you can set your maxQueryStringLength
在你的 web.config<system.web> <httpRuntime>标签下,你可以设置你的maxQueryStringLength
so its like
所以它就像
<system.web>
<httpRuntime maxQueryStringLength = "**MY NUMBER**" />
</system.web>
check out the msdn reference : http://msdn.microsoft.com/en-us/library/e1f13641%28v=vs.100%29.aspx
查看 msdn 参考:http: //msdn.microsoft.com/en-us/library/e1f13641%28v=vs.100%29.aspx
Also please increase maxQueryStringLength in the IIS configuration, check out :
另外请在 IIS 配置中增加 maxQueryStringLength,查看:
http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
回答by theJerm
In the root web.configfor your project, under the system.webnode:
在web.config您项目的根目录中的system.web节点下:
<system.web>
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
...
In addition, I had to add this under the system.webServernode or I got a security error for my long query strings:
此外,我必须在system.webServer节点下添加它,否则我的长查询字符串会出现安全错误:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="9999" />
</requestFiltering>
</security>
...
回答by Nguy?n Thành Ngh?a
I fixed follow: It run Ok
我修复了以下问题:它运行正常
<system.webServer>
<security>
<requestFiltering>
<alwaysAllowedQueryStrings>
<add queryString="maxQueryString" />
<add queryString="maxAllowedContentLength" />
<add queryString="maxUrl" />
</alwaysAllowedQueryStrings>
<requestLimits maxUrl="10999" maxQueryString="2097151" />
</requestFiltering>
</security>
</system.webServer>
And add
并添加
<system.web>
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
</system.web>

