gpt4 book ai didi

asp.net - 为什么当输入很大时 asp.net 找不到合适的 apicontroller?

转载 作者:行者123 更新时间:2023-12-02 04:42:39 25 4
gpt4 key购买 nike

我有一个功能可以一次性保存我的实体列表。

public void Save(IEnumerable<SubjectData> subjectDatas)
{
var request = _requestFactory.CreateRequest("api/subjectData", Method.POST, AccessToken.AccessToken, new List<SubjectData>(subjectDatas));
var response = Client.Execute(request);
_responseDeserializer.Deserialize<SubjectData>(response);
}

那是调用一个 wep API 函数:

// POST api/<controller>
public void Post([FromBody]List<SubjectData> values)
{
_subjectDataService.Save(values, User.Identity.Name);
}

当我 subjectDatas 是一个大约 30 的列表时,这工作正常。但是,当 subjectDatas 非常大时(在我的测试用例中,超过 96000),我会收到意外错误。响应具有 StatusCode NotFound。这是怎么回事?为什么突然找不到合适的 Controller ?

最佳答案

根据这些答案

Is there a limit on how much JSON can hold?

How to increase the json size limit for ASP.NET WebAPI Post call?

引用一些资料

An ASP.NET request that has lots of form keys, files, or JSON payload members fails with an exception

JavaScriptSerializer.MaxJsonLength Property

似乎有一个默认的 ASP.Net 可以解析的最大数据大小,为了增加它,您必须对 web.config

进行一些更改

这是提供的建议之一:

Try adding the aspnet:MaxJsonDeserializerMembers under appSettings in web.config

<add key="aspnet:MaxJsonDeserializerMembers" value="20000"/>

另一个引用来源:

Applications that hit this limit for JSON payloads can modify the ASP.NET appSetting aspnet:MaxJsonDeserializerMembers, as shown below in an ASP.NET application’s configuration file. This setting addresses error message 3 from the "Symptoms" section.

<configuration>
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="1000" />
</appSettings>
</configuration>

Note Increasing this value above the default setting increases the susceptibility of your server to the Denial of Service vulnerability that is discussed in security bulletin MS11-100.

关于asp.net - 为什么当输入很大时 asp.net 找不到合适的 apicontroller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36223131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com