web.config에서 maxJsonLength의 길이를 무제한으로 설정할 수 있습니까?
jQuery의 자동 완성 기능을 사용하고 있습니다.17000개 이상의 레코드(각 레코드의 길이는 10자를 넘지 않음)의 리스트를 취득하려고 하면, 이 레코드는 길이를 넘고, 에러가 발생합니다.
정보: " " " " :
"Invalid " "Exception" 입니다.
"Serializer를 또는 중 가 발생하였습니다.JSON JavaScript Serializer 。maxJsonLength를 선택합니다.
의 길이를 무제한으로 설정할 수 있습니까?maxJsonLengthweb.config설정되지 않은 경우 설정할 수 있는 최대 길이는 얼마입니까?
메모: 이 답변은 웹 서비스에만 적용됩니다.컨트롤러 메서드에서 JSON을 반환하는 경우 다음 SO 답변도 읽어보십시오.https://stackoverflow.com/a/7207539/1246870
MaxJsonLength 속성은 무제한일 수 없습니다.기본값은 102400(100k)인 정수 속성입니다.
설정할 수 요.MaxJsonLength web.config :
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
에러가 아직 표시되는 경우는, 다음의 순서에 따릅니다.
- 를 한 후
maxJsonLengthweb. web.config의 합니다. - 데이터 길이가 이 값보다 작다는 것을 알 수 있습니다.
- JavaScript serialization에 웹 서비스 방식을 사용하지 않습니다.
다음과 같은 문제가 있을 수 있습니다.
MaxJsonLength 속성 값은 웹 서비스 메서드를 호출하기 위해 비동기 통신 계층에서 사용되는 내부 JavaScriptSerializer 인스턴스에만 적용됩니다(MSDN: ScriptingJsonSerialization Section).MaxJsonLength 속성)
는 '내부'입니다.JavaScriptSerializer를 maxJsonLength; " " " " " 직접 , " "JavaScriptSerializer(또는 MVC 액션 방식/컨트롤러 경유로 사용)는 다음 조건을 준수하지 않습니다.maxJsonLength 「」의 것은 아니다)systemWebExtensions.scripting.webServices.jsonSerializationweb.config 섹션입니다.특히 이 메서드는 구성 설정을 따르지 않습니다.
회피책으로서 컨트롤러 내(또는 실제 장소)에서 다음 작업을 수행할 수 있습니다.
var serializer = new JavaScriptSerializer();
// For simplicity just use Int32's max value.
// You could always read the value from the config section mentioned above.
serializer.MaxJsonLength = Int32.MaxValue;
var resultData = new { Value = "foo", Text = "var" };
var result = new ContentResult{
Content = serializer.Serialize(resultData),
ContentType = "application/json"
};
return result;
이 답변은 asp.net 포럼 답변에 대한 저의 해석입니다.
MVC 4에서는 다음 작업을 수행할 수 있습니다.
protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
{
return new JsonResult()
{
Data = data,
ContentType = contentType,
ContentEncoding = contentEncoding,
JsonRequestBehavior = behavior,
MaxJsonLength = Int32.MaxValue
};
}
컨트롤러에 접속합니다.
추가:
지정할 필요가 있는 파라미터에 곤혹스러운 사람은, 다음과 같은 콜이 있습니다.
Json(
new {
field1 = true,
field2 = "value"
},
"application/json",
Encoding.UTF8,
JsonRequestBehavior.AllowGet
);
web.config 파일에서 json 요청의 최대 길이를 설정할 수 있습니다.
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="....">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
maxJsonLength 기본값은 102400입니다.상세한 것에 대하여는, 다음의 MSDN 페이지를 참조해 주세요.http://msdn.microsoft.com/en-us/library/bb763183.aspx
web.config 설정 후에도 다음과 같은 오류가 발생할 경우:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
다음과 같이 해결했습니다.
public ActionResult/JsonResult getData()
{
var jsonResult = Json(superlargedata, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
이게 도움이 되었으면 좋겠어요.
ASP에서 이 문제가 발생했습니다.NET Web 폼web.config 파일 설정을 완전히 무시하고 있었기 때문에 다음과 같이 했습니다.
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
return serializer.Serialize(response);
물론 전반적으로 이것은 끔찍한 관행이다.웹 서비스 호출로 이만큼의 데이터를 전송하는 경우 다른 방법을 검토해야 합니다.
나는 잔존자의 대답을 따라 이 해결책에 도달했다.
컨트롤러의 액션에 큰 json을 게시해야 할 때 유명한 "Error during deserialization using the JSON JavaScript Serializer"가 표시됩니다.문자열 길이가 maxJsonLength 속성에 설정된 값을 초과합니다.\r\n 파라미터 이름: 입력값 공급자"입니다.
새로운 ValueProviderFactory LargeJsonValueProviderFactory를 만들고 MaxJsonLength = Int32를 설정했습니다.GetDeserializedObject 메서드의 MaxValue
public sealed class LargeJsonValueProviderFactory : ValueProviderFactory
{
private static void AddToBackingStore(LargeJsonValueProviderFactory.EntryLimitedDictionary backingStore, string prefix, object value)
{
IDictionary<string, object> dictionary = value as IDictionary<string, object>;
if (dictionary != null)
{
foreach (KeyValuePair<string, object> keyValuePair in (IEnumerable<KeyValuePair<string, object>>) dictionary)
LargeJsonValueProviderFactory.AddToBackingStore(backingStore, LargeJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
}
else
{
IList list = value as IList;
if (list != null)
{
for (int index = 0; index < list.Count; ++index)
LargeJsonValueProviderFactory.AddToBackingStore(backingStore, LargeJsonValueProviderFactory.MakeArrayKey(prefix, index), list[index]);
}
else
backingStore.Add(prefix, value);
}
}
private static object GetDeserializedObject(ControllerContext controllerContext)
{
if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
return (object) null;
string end = new StreamReader(controllerContext.HttpContext.Request.InputStream).ReadToEnd();
if (string.IsNullOrEmpty(end))
return (object) null;
var serializer = new JavaScriptSerializer {MaxJsonLength = Int32.MaxValue};
return serializer.DeserializeObject(end);
}
/// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
/// <returns>A JSON value-provider object for the specified controller context.</returns>
/// <param name="controllerContext">The controller context.</param>
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
if (controllerContext == null)
throw new ArgumentNullException("controllerContext");
object deserializedObject = LargeJsonValueProviderFactory.GetDeserializedObject(controllerContext);
if (deserializedObject == null)
return (IValueProvider) null;
Dictionary<string, object> dictionary = new Dictionary<string, object>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
LargeJsonValueProviderFactory.AddToBackingStore(new LargeJsonValueProviderFactory.EntryLimitedDictionary((IDictionary<string, object>) dictionary), string.Empty, deserializedObject);
return (IValueProvider) new DictionaryValueProvider<object>((IDictionary<string, object>) dictionary, CultureInfo.CurrentCulture);
}
private static string MakeArrayKey(string prefix, int index)
{
return prefix + "[" + index.ToString((IFormatProvider) CultureInfo.InvariantCulture) + "]";
}
private static string MakePropertyKey(string prefix, string propertyName)
{
if (!string.IsNullOrEmpty(prefix))
return prefix + "." + propertyName;
return propertyName;
}
private class EntryLimitedDictionary
{
private static int _maximumDepth = LargeJsonValueProviderFactory.EntryLimitedDictionary.GetMaximumDepth();
private readonly IDictionary<string, object> _innerDictionary;
private int _itemCount;
public EntryLimitedDictionary(IDictionary<string, object> innerDictionary)
{
this._innerDictionary = innerDictionary;
}
public void Add(string key, object value)
{
if (++this._itemCount > LargeJsonValueProviderFactory.EntryLimitedDictionary._maximumDepth)
throw new InvalidOperationException("JsonValueProviderFactory_RequestTooLarge");
this._innerDictionary.Add(key, value);
}
private static int GetMaximumDepth()
{
NameValueCollection appSettings = ConfigurationManager.AppSettings;
if (appSettings != null)
{
string[] values = appSettings.GetValues("aspnet:MaxJsonDeserializerMembers");
int result;
if (values != null && values.Length > 0 && int.TryParse(values[0], out result))
return result;
}
return 1000;
}
}
}
그런 다음 Global.asax.cs의 Application_Start 메서드에서 ValueProviderFactory를 새 것으로 바꿉니다.
protected void Application_Start()
{
...
//Add LargeJsonValueProviderFactory
ValueProviderFactory jsonFactory = null;
foreach (var factory in ValueProviderFactories.Factories)
{
if (factory.GetType().FullName == "System.Web.Mvc.JsonValueProviderFactory")
{
jsonFactory = factory;
break;
}
}
if (jsonFactory != null)
{
ValueProviderFactories.Factories.Remove(jsonFactory);
}
var largeJsonValueProviderFactory = new LargeJsonValueProviderFactory();
ValueProviderFactories.Factories.Add(largeJsonValueProviderFactory);
}
난 그걸 고쳤어.
//your Json data here
string json_object="........";
JavaScriptSerializer jsJson = new JavaScriptSerializer();
jsJson.MaxJsonLength = 2147483644;
MyClass obj = jsJson.Deserialize<MyClass>(json_object);
그것은 매우 잘 작동한다.
"web.config" "Unrecognized configuration section system ( " " " " " " " " " " " ". " " " 、 web . extensions " . inconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfigconfig 。<ConfigSections>★★★★
<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>
MVC의 Action 메서드에서 MaxJsonLength 프로그램을 설정하기만 하면 됩니다.
JsonResult json= Json(classObject, JsonRequestBehavior.AllowGet);
json.MaxJsonLength = int.MaxValue;
return json;
이 행을 컨트롤러에 쓸 수 있습니다.
json.MaxJsonLength = 2147483644;
도 이 쓸 수 요.web.config
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
`
안전을 위해 둘 다 사용하세요.
ASP 수정NET MVC를 문제의 원인이 되는 특정 액션에만 수정하려면 다음 코드를 변경하십시오.
public JsonResult GetBigJson()
{
var someBigObject = GetBigObject();
return Json(someBigObject);
}
다음과 같이 입력합니다.
public JsonResult GetBigJson()
{
var someBigObject = GetBigObject();
return new JsonResult()
{
Data = someBigObject,
JsonRequestBehavior = JsonRequestBehavior.DenyGet,
MaxJsonLength = int.MaxValue
};
}
또한 기능은 동일해야 하며, 응답으로 더 큰 JSON을 반환할 수 있습니다.
ASP の asp asp 。 MVC 코드: NET MVC를 할 수 .Controller.JsonASP에서는 method가 합니다.NET MVC 소스 코드
protected internal JsonResult Json(object data)
{
return Json(data, null /* contentType */, null /* contentEncoding */, JsonRequestBehavior.DenyGet);
}
다른 메서드를 호출하고 있습니다.
protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
{
return new JsonResult
{
Data = data,
ContentType = contentType,
ContentEncoding = contentEncoding,
JsonRequestBehavior = behavior
};
}
한 곳contentType ★★★★★★★★★★★★★★★★★」contentEncoding오브젝트는 다음과 같습니다.null으로는 '콜링'입니다return Json(object)는 controller를 호출하는 것과 .return new JsonResult { Data = object, JsonRequestBehavior = sonRequestBehavior.DenyGet } 형식을 를 지정할 수 JsonResult.
'만나서'를 되나요?MaxJsonLength속성(디폴트로는 무효)에 전해지고 있다JavaScriptSerializer.MaxJsonLength[ ]에 이어 [Property]를 합니다.JavaScriptSerializer.Serialize메서드는 다음과 같습니다.
JavaScriptSerializer serializer = new JavaScriptSerializer();
if (MaxJsonLength.HasValue)
{
serializer.MaxJsonLength = MaxJsonLength.Value;
}
if (RecursionLimit.HasValue)
{
serializer.RecursionLimit = RecursionLimit.Value;
}
response.Write(serializer.Serialize(Data));
, 설정되지 않은 는,MaxJsonLenght serializer의 속성은 기본값인 2MB를 취합니다.
MVC의 MiniProfiler에서 이 오류가 발생할 경우 속성을 설정하여 값을 늘릴 수 있습니다.MiniProfiler.Settings.MaxJsonResponseSize원하는 값으로 이동합니다.기본적으로는 이 도구는 config에서 설정된 값을 무시하는 것으로 보입니다.
MiniProfiler.Settings.MaxJsonResponseSize = 104857600;
MVC 미니 프로파일러를 준비했습니다
Int32로 설정할 것을 권장합니다.최대값
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
속성 마법은 어때?
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class MaxJsonSizeAttribute : ActionFilterAttribute
{
// Default: 10 MB worth of one byte chars
private int maxLength = 10 * 1024 * 1024;
public int MaxLength
{
set
{
if (value < 0) throw new ArgumentOutOfRangeException("value", "Value must be at least 0.");
maxLength = value;
}
get { return maxLength; }
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
JsonResult json = filterContext.Result as JsonResult;
if (json != null)
{
if (maxLength == 0)
{
json.MaxJsonLength = int.MaxValue;
}
else
{
json.MaxJsonLength = maxLength;
}
}
}
}
그런 다음 글로벌필터 설정 또는 컨트롤러/액션 중 하나를 사용하여 글로벌하게 적용할 수 있습니다.
View에서 이러한 문제가 발생할 경우 다음 방법을 사용하여 해결할 수 있습니다.여기 Newtonsoft 패키지가 있습니다.
@using Newtonsoft.Json
<script type="text/javascript">
var partData = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Part));
</script>
대체 ASPNET MVC 5 수정:
(MFC는 위의 답변과 비슷하지만 몇 가지 작은 변경 사항이 있습니다.)
Json Json입니다.NET에 의한 것입니다.내 시나리오에서 가장 좋은 방법은 실제를 수정하는 것이다.JsonValueProviderFactory되며 수정은 글로벌프로젝트에 수정은 글로벌프로젝트에 됩니다.global.cs파일링을 합니다.
JsonValueProviderConfig.Config(ValueProviderFactories.Factories);
web.config 엔트리를 추가합니다.
<add key="aspnet:MaxJsonLength" value="20971520" />
그리고 다음 두 개의 클래스를 만듭니다.
public class JsonValueProviderConfig
{
public static void Config(ValueProviderFactoryCollection factories)
{
var jsonProviderFactory = factories.OfType<JsonValueProviderFactory>().Single();
factories.Remove(jsonProviderFactory);
factories.Add(new CustomJsonValueProviderFactory());
}
}
으로 에 .System.Web.Mvc, 설정 값 「」이 추가되어 「web.config appsetting」이 추가되어 있습니다.aspnet:MaxJsonLength.
public class CustomJsonValueProviderFactory : ValueProviderFactory
{
/// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
/// <returns>A JSON value-provider object for the specified controller context.</returns>
/// <param name="controllerContext">The controller context.</param>
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
if (controllerContext == null)
throw new ArgumentNullException("controllerContext");
object deserializedObject = CustomJsonValueProviderFactory.GetDeserializedObject(controllerContext);
if (deserializedObject == null)
return null;
Dictionary<string, object> strs = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
CustomJsonValueProviderFactory.AddToBackingStore(new CustomJsonValueProviderFactory.EntryLimitedDictionary(strs), string.Empty, deserializedObject);
return new DictionaryValueProvider<object>(strs, CultureInfo.CurrentCulture);
}
private static object GetDeserializedObject(ControllerContext controllerContext)
{
if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
return null;
string fullStreamString = (new StreamReader(controllerContext.HttpContext.Request.InputStream)).ReadToEnd();
if (string.IsNullOrEmpty(fullStreamString))
return null;
var serializer = new JavaScriptSerializer()
{
MaxJsonLength = CustomJsonValueProviderFactory.GetMaxJsonLength()
};
return serializer.DeserializeObject(fullStreamString);
}
private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
{
IDictionary<string, object> strs = value as IDictionary<string, object>;
if (strs != null)
{
foreach (KeyValuePair<string, object> keyValuePair in strs)
CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
return;
}
IList lists = value as IList;
if (lists == null)
{
backingStore.Add(prefix, value);
return;
}
for (int i = 0; i < lists.Count; i++)
{
CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakeArrayKey(prefix, i), lists[i]);
}
}
private class EntryLimitedDictionary
{
private static int _maximumDepth;
private readonly IDictionary<string, object> _innerDictionary;
private int _itemCount;
static EntryLimitedDictionary()
{
_maximumDepth = CustomJsonValueProviderFactory.GetMaximumDepth();
}
public EntryLimitedDictionary(IDictionary<string, object> innerDictionary)
{
this._innerDictionary = innerDictionary;
}
public void Add(string key, object value)
{
int num = this._itemCount + 1;
this._itemCount = num;
if (num > _maximumDepth)
{
throw new InvalidOperationException("The length of the string exceeds the value set on the maxJsonLength property.");
}
this._innerDictionary.Add(key, value);
}
}
private static string MakeArrayKey(string prefix, int index)
{
return string.Concat(prefix, "[", index.ToString(CultureInfo.InvariantCulture), "]");
}
private static string MakePropertyKey(string prefix, string propertyName)
{
if (string.IsNullOrEmpty(prefix))
{
return propertyName;
}
return string.Concat(prefix, ".", propertyName);
}
private static int GetMaximumDepth()
{
int num;
NameValueCollection appSettings = ConfigurationManager.AppSettings;
if (appSettings != null)
{
string[] values = appSettings.GetValues("aspnet:MaxJsonDeserializerMembers");
if (values != null && values.Length != 0 && int.TryParse(values[0], out num))
{
return num;
}
}
return 1000;
}
private static int GetMaxJsonLength()
{
int num;
NameValueCollection appSettings = ConfigurationManager.AppSettings;
if (appSettings != null)
{
string[] values = appSettings.GetValues("aspnet:MaxJsonLength");
if (values != null && values.Length != 0 && int.TryParse(values[0], out num))
{
return num;
}
}
return 1000;
}
}
모델 바인더를 위해 자동으로 역직렬화되고 크기가 너무 큰 JSON을 사용하는 MVC3에서 문제가 있는 사용자를 위해 다음과 같은 해결책이 있습니다.
- MVC3 소스 코드에서 Json Value Provider Factory 클래스의 코드를 새 클래스로 복사합니다.
- 오브젝트가 역직렬화되기 전에 최대 JSON 길이를 변경하려면 행을 추가합니다.
- Json Value Provider Factory 클래스를 변경된 새 클래스로 바꿉니다.
http://blog.naver.com/techshare/100145191355과 https://gist.github.com/DalSoft/1588818에서 올바른 방법을 가르쳐 주셔서 감사합니다.첫 번째 사이트의 마지막 링크에는 솔루션의 전체 소스 코드가 포함되어 있습니다.
문제는 정말 17k 레코드를 반환할 필요가 있느냐는 것입니다.브라우저의 모든 데이터를 어떻게 처리할 예정입니까?사용자는 17000 행을 스크롤하지 않습니다.
더 나은 방법은 "상위 몇 개" 레코드만 가져오고 필요에 따라 더 많이 로드하는 것입니다.
다른 사용자가 말한 대로 Configuration으로 설정할 수도 있고 다음과 같이 시리얼라이저의 개별 인스턴스에 설정할 수도 있습니다.
var js = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };
JsonResult result = Json(r);
result.MaxJsonLength = Int32.MaxValue;
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
"무제한" 값은 없는 것 같습니다.기본값은 2097152 문자이며, 이는 4 MB의 Unicode 문자열 데이터에 해당합니다.
이미 관찰한 바와 같이 17,000개의 레코드는 브라우저에서 잘 활용하기 어렵다.집약 뷰를 표시하는 경우는, 서버상에서 집약을 실시해, 브라우저로 요약만을 전송 하는 것이 훨씬 효율적일 수 있습니다.예를 들어 파일 시스템 브라우저를 예로 들 수 있습니다. 트리 맨 위만 보고 드릴다운할 때 추가 요청을 보냅니다.각 요청에서 반환되는 레코드 수는 비교적 적습니다.트리 뷰 프레젠테이션은 큰 결과 세트에 적합합니다.
방금 이걸 만났어음반이 6천 장이 넘어요그냥 호출기로 했어요에서와 같이 MVC JsonResult 엔드포인트의 페이지 번호를 수락합니다. 기본값은 0이므로 다음과 같이 필요하지 않습니다.
public JsonResult MyObjects(int pageNumber = 0)
그럼 이렇게 말하는 게 아니라
return Json(_repository.MyObjects.ToList(), JsonRequestBehavior.AllowGet);
나는 말한다:
return Json(_repository.MyObjects.OrderBy(obj => obj.ID).Skip(1000 * pageNumber).Take(1000).ToList(), JsonRequestBehavior.AllowGet);
아주 간단해요.그 후 JavaScript에서는 다음과 같이 입력합니다.
function myAJAXCallback(items) {
// Do stuff here
}
대신 이렇게 말하죠.
var pageNumber = 0;
function myAJAXCallback(items) {
if(items.length == 1000)
// Call same endpoint but add this to the end: '?pageNumber=' + ++pageNumber
}
// Do stuff here
}
그리고 애초에 그들과 함께 했던 것에 기록을 첨부하세요.아니면 모든 통화가 끝날 때까지 기다렸다가 결과를 종합해 보세요.
이 코드를 추가하는 문제를 해결했습니다.
String confString = HttpContext.Current.Request.ApplicationPath.ToString();
Configuration conf = WebConfigurationManager.OpenWebConfiguration(confString);
ScriptingJsonSerializationSection section = (ScriptingJsonSerializationSection)conf.GetSection("system.web.extensions/scripting/webServices/jsonSerialization");
section.MaxJsonLength = 6553600;
conf.Save();
WebForms UpdatePanel 솔루션:
Web.config에 설정을 추가합니다.
<configuration>
<appSettings>
<add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
</appSettings>
</configuration>
https://support.microsoft.com/en-us/kb/981884
ScriptRegistrationManager클래스에 다음 코드가 포함되어 있습니다.
// Serialize the attributes to JSON and write them out
JavaScriptSerializer serializer = new JavaScriptSerializer();
// Dev10# 877767 - Allow configurable UpdatePanel script block length
// The default is JavaScriptSerializer.DefaultMaxJsonLength
if (AppSettings.UpdatePanelMaxScriptLength > 0) {
serializer.MaxJsonLength = AppSettings.UpdatePanelMaxScriptLength;
}
string attrText = serializer.Serialize(attrs);
서버 측 변경은 필요 없습니다.web.config 파일로만 수정할 수 있습니다.이것이 도움이 되었습니다.이것을 사용해 보세요.
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
<add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
</appSettings>
and
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
나는 이것을 사용했고 그것은 검도 그리드 읽기 요청에 효과가 있었다.
{
//something
var result = XResult.ToList().ToDataSourceResult(request);
var rs = Json(result, JsonRequestBehavior.AllowGet);
rs.MaxJsonLength = int.MaxValue;
return rs;
}
lib\Newtonsoft.Json.dll
public string serializeObj(dynamic json) {
return JsonConvert.SerializeObject(json);
}
이 maxJsonLength 값이 int일 경우 int 32bit/64bit/16bit...maxJsonLength로 설정할 수 있는 최대값이 얼마인지 확인하려고 합니다.
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647">
</jsonSerialization>
</webServices>
</scripting>
web.config를 사용할 필요가 없습니다. 통과 목록의 캐치 값 동안 짧은 속성을 사용할 수 있습니다. 예를 들어 다음과 같은 모델을 선언합니다.
public class BookModel
{
public decimal id { get; set; } // 1
public string BN { get; set; } // 2 Book Name
public string BC { get; set; } // 3 Bar Code Number
public string BE { get; set; } // 4 Edition Name
public string BAL { get; set; } // 5 Academic Level
public string BCAT { get; set; } // 6 Category
}
여기서는 BC =book be =book edition 등의 짧은 비율을 사용합니다.
언급URL : https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config
'programing' 카테고리의 다른 글
| JSON 어레이의 foreach, 구문 (0) | 2023.03.06 |
|---|---|
| JSON 결과에서 함수를 정의하는 것이 유효한가? (0) | 2023.03.06 |
| SpringBoot 주 매니페스트 특성 없음(매븐) (0) | 2023.03.06 |
| javax.servlet.spring 웹 앱의 형식으로 ServletException을 확인할 수 없습니다. (0) | 2023.03.06 |
| reactJ의 파일 명명 규칙? (0) | 2023.03.06 |