简体   繁体   English

如何在webapi中配置maxQueryStringLength?

[英]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.

相关问题 如何为webapi配置此路由? - how to configure this route for webapi? 如何在Webapi .net Core 2.2中配置自定义终结点 - How to configure custom endpoint in webapi .net core 2.2 如何配置C#WebApi HTTP DELETE响应 - How to configure c# WebApi HTTP DELETE response 如何在 .NET Core 2.2 WebApi 和 Azure AD 2.0 中配置 Swagger? - How to Configure Swagger in .NET Core 2.2 WebApi and Azure AD 2.0? 如何在ASP.Net WebApi中正确配置路由问题 - How to correctly configure a route issue in ASP.Net WebApi 配置 Blazor 服务器以托管 WebAPI - Configure Blazor Server to host WebAPI 为WebApi控制器配置请求超时 - Configure request timeout for WebApi controllers 如何使用WebAPI,WCF,SignalR和后台任务在MVC Web应用程序中配置简单的注入器容器和lifestylse - How to configure simple injector container and lifestylse in a MVC web app with WebAPI, WCF, SignalR and Background Task 在C#WebAPI中,如何配置CORS以允许具有凭据和JSON内容的POST请求? - In C# WebAPI, how do I configure CORS to allow a POST request with credentials and json content? 如何使用.Net Core WebApi将Azure CDN与前端SPA和Azure WebApp配置到相同的自定义域? - How to configure Azure CDN with front-end SPA and Azure WebApp with .Net Core WebApi to same custom domain?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM