jQuery 在 ASP.net Web.Config 中设置 jsonSerialization maxJsonLength 给出 500 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12750689/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:59:39  来源:igfitidea点击:

setting jsonSerialization maxJsonLength in ASP.net Web.Config gives 500 error

jqueryajaxweb-configwebmethod

提问by

So, I keep getting the 500 - Internal server error page on my .net site when I set the maxJsonLength in my web.config.

因此,当我在 web.config 中设置 maxJsonLength 时,我不断在我的 .net 站点上看到 500 - Internal server error 页面。

I'm modifying the .config because even though I use MaxJsonLength = Int32.MaxValue on my vb.net JavaScriptSerializer, I'm still getting InvalidOperationException for a large dictionary i'm trying to transmit even though it's well below the 4GB the MaxJsonLength @ Int32.MaxValue allows or even the supposed 4mb default limit.

我正在修改 .config,因为即使我在 vb.net JavaScriptSerializer 上使用 MaxJsonLength = Int32.MaxValue,我仍然收到 InvalidOperationException 对于我正在尝试传输的大型字典,即使它远低于 MaxJsonLength @ 的 4GB Int32.MaxValue 允许甚至假定的 4mb 默认限制。

I'm using toolkitscriptmanager if that means anything.

如果这意味着什么,我正在使用 toolkitscriptmanager。

  <system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="2147483647"/>
  </webServices>
</scripting>

this didn't help (actually, it also gives 500 error without above code)

这没有帮助(实际上,如果没有上述代码,它也会给出 500 错误)

<sectionGroup name="system.web.extensions" type="System.Web.Extensions">
  <sectionGroup name="scripting" type="System.Web.Extensions">
    <sectionGroup name="webServices" type="System.Web.Extensions">
      <section name="jsonSerialization" type="System.Web.Extensions"/>
    </sectionGroup>
  </sectionGroup>
</sectionGroup>

heard this should help with InvalidOperationException, but it didn't. I took it out, and still 500 error.

听说这应该有助于 InvalidOperationException,但它没有。我拿出来,还是500错误。

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

Many thanks in advance!

提前谢谢了!

Edit

编辑

Same problem, but his solution doesn't work for me. The last code he added also gives 500 error. Problem with <system.web.extensions> config group when upgrading to .NET 4.0

同样的问题,但他的解决方案对我不起作用。他添加的最后一个代码也给出了 500 错误。 升级到 .NET 4.0 时 <system.web.extensions> 配置组出现问题

采纳答案by

The problem for me was that I put the code in the beginning of the web.config. For some reason, putting it at the end worked.

我的问题是我把代码放在 web.config 的开头。出于某种原因,把它放在最后是有效的。

Not an expert, so I have no idea why that worked.

不是专家,所以我不知道为什么会这样。

It worked without the last two code sections that I tried to make it work.

它在没有我试图让它工作的最后两个代码部分的情况下工作。

回答by madhu_sudhan

I agreed with Gracchus, I put this below block in end of web.config file

我同意 Gracchus,我把它放在 web.config 文件末尾的块下面

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647"/>
        </webServices>
    </scripting>
</system.web.extensions>`

回答by Raza

<system.web.extensions>
    <scripting>
      <webServices>
        <!--<jsonSerialization maxJsonLength="50000000">
        </jsonSerialization>-->
        <jsonSerialization maxJsonLength="500000000">
          <!--50000000-->
        </jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>  

Above settings worked for me. Additionally i had to set the target framework of the website to .Net 4.0. This web config setting was giving me 500 errorwhen the target framework was set to .Net 2.0

以上设置对我有用。此外,我必须将网站的目标框架设置为 .Net 4.0。当目标框架设置为 .Net 2.0 时,此 Web 配置设置给了我500 错误

To change the framework, goto IIS and select Application PoolRight click on your website name and select Advanced settings. Here you can change the .Net Framework Version by clicking on the drop-down.

要更改框架,请转到 IIS 并选择应用程序池右键单击您的网站名称并选择高级设置。在这里,您可以通过单击下拉菜单来更改 .Net Framework 版本。

Also i had this setting at the bottom of the web config. Only for good luck :)

我也在网络配置的底部有这个设置。只为祝你好运:)

Hope this helps.

希望这可以帮助。