[英]How to configure maxQueryStringLength in webapi?
I wrote a method in webapi that get data by json format. 我在webapi中编写了一种以json格式获取数据的方法。 This work currently but when I call this method by another parameters that length of query string is 2154 character get me error that : 当前可以正常工作,但是当我通过另一个参数调用该方法时,查询字符串的长度为2154个字符,会收到以下错误消息:
The length of the query string for this request exceeds the configured maxQueryStringLength value. 此请求的查询字符串的长度超过了配置的maxQueryStringLength值。
Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
Exception Details: System.Web.HttpException: The length of the query string for this request exceeds the configured maxQueryStringLength value. 异常详细信息:System.Web.HttpException:此请求的查询字符串的长度超过了配置的maxQueryStringLength值。
I add to webconfig below code inside system.webServer
section 我在system.webServer
部分中的代码下面添加到webconfig
<security>
<requestFiltering>
<requestLimits maxQueryString="5000" maxUrl="5000" maxAllowedContentLength="102400000" />
</requestFiltering>
</security>
but don't solved. 但没有解决。
webapi method : webapi方法:
[HttpPost,HttpGet]
public IHttpActionResult LockSeats(string ticketsJson, bool checkCompartment, string userId, string ipAddress)
{
try
{
List<WagonAvaliableResponse> tickets = JsonConvert.DeserializeObject<List<WagonAvaliableResponse>>(ticketsJson);
AdakTrainLibrary.ResultLockSeat resultLockSeat = _adakTrain.LockSeats(tickets, 1, 1, "1", "1", checkCompartment, userId, ipAddress, TrainUserId, TrainPass);
return Ok(resultLockSeat);
}
catch (Exception e)
{
return Ok(e);
}
}
How can i fix this? 我怎样才能解决这个问题?
I add this code into system.webServer
section 我将此代码添加到system.webServer
部分
<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 进入system.web
部分并解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.