VB   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了vb.net – Web.config jsonSerialization maxJsonLength被忽略大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个在.NET 4.0下运行的MVC3应用程序,当我使用 Javascriptserializer.Deserialize时,我收到一个错误.

阅读Can I set an unlimited length for maxJsonLength in web.config我将jsonserialization maxJsonLength键放在我的web.config中,但它被忽略了.然我可以在代码中设置JavaScriptserializer.MaxJsonLength属性,但它工作正常.

我想在Web.config而不是代码中获得值.以下是我使用JavaScriptserializer的方法.

Dim client As New WebClient
...
Dim result = _client.DownloadString("Test")
Dim serializer = New JavaScriptserializer
Return serializer.Deserialize(Of Foo)(result)

这是我的Web.config

<configuration>
    <configSections>
    ...
    </configSections>
    <appSetTings>
    ...
    </appSetTings>
    <system.web>
    <customErrors mode="On">
      <error statusCode="404" redirect="/http404"/>
      <error statusCode="403" redirect="/http403"/>
      <error statusCode="550" redirect="/http550"/>
    </customErrors>
    <compilation debug="true" targetFramework="4.0"/>
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Helpers"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.RoutIng"/>
        <add namespace="System.Web.WebPages"/>
      </namespaces>
    </pages>
  </system.web>
  <system.web.extensions>
    <scripTing>
      <webservices>
        <jsonserialization maxJsonLength="50000000"/>
      </webservices>
    </scripTing>
    </system.web.extensions>
 <system.webServer>
 ....
</system.webServer>
</configuration>
根据您提供的链接(排名第二的答案),您的web.config设置将被忽略,因为您正在使用JavaScriptserializer的内部实例.

如果您需要将值存储在web.config中,则可以在< appSetTings>中添加一个键.名为maxJsonLength的部分,值为50000000,然后在您的代码中,您可以使用它:

var serializer = new JavaScriptserializer();
serializer.MaxJsonLength = ConfigurationManager.AppSetTings['maxJsonLength'];

大佬总结

以上是大佬教程为你收集整理的vb.net – Web.config jsonSerialization maxJsonLength被忽略全部内容,希望文章能够帮你解决vb.net – Web.config jsonSerialization maxJsonLength被忽略所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。