Ho un'applicazione MVC3
in esecuzione su .NET 4.0
e quando utilizzo JavascriptSerializer.Deserialize
, si verifica un errore.Web.config jsonSerialization maxJsonLength ignorato
Errore durante la serializzazione o deserializzazione mediante JavaScript JSerializer. La lunghezza della stringa supera il valore impostato sulla proprietà maxJsonLength.
lettura Can I set an unlimited length for maxJsonLength in web.config ho messo la chiave jsonSerialization maxJsonLength
nel mio web.config, ma viene ignorato. Anche se posso impostare la proprietà JavaScriptSerializer.MaxJsonLength
nel codice e funziona correttamente.
Mi piacerebbe avere il valore nel codice Web.config
anziché codice. Ecco come sto usando JavaScriptSerializer
.
Dim client As New WebClient
...
Dim result = _client.DownloadString("Test")
Dim serializer = New JavaScriptSerializer
Return serializer.Deserialize(Of Foo)(result)
Ecco il mio 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>
Dovresti evidenziare ** istanza interna **. Questo è ciò che ho letto male! –
Fatto. Inoltre ho appena realizzato che ti ho dato un esempio in C#, non ho visto il tuo tag vb.net fino ad ora :) – lhan