Base64字符串太长,无法进行序列化

时间:2018-01-09 11:37:06

标签: javascript c# json ajax serialization

在我的门户网站中,我将数据发布到包含base64字符串的控制器。此字符串的长度太长,因此在下面出现错误;

  

使用JSON进行序列化或反序列化时出错   JavaScriptSerializer。字符串的长度超过了设置的值   在maxJsonLength属性上。参数名称:输入

在代码中;在视图中我使用了AJAX帖子

            var item = {
                Title: title,
                SeoUrl: seo,
                IsActive: isActive,
                Portals: portals,
                Content: content,
                Lang: pageLanguage,
                IsShown:isLock,
                MetaKeywords:keywords,
                MetaDescription:description
            }
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("Add", "Page")',
                    data: JSON.stringify(item),                
                    success: function(data) {
                        if (data.Result !== "SUCCEED") {
                            if (data.Result == "SEO_URL_EXISTS") {

                                toastr.warning('Böyle bir seo_url mevcuttur !!!');
                                return;
                            }
                            toastr.error('@Resources.Resource.Error_Unexpected');
                            return;
                        }
                        if (!isActive) {
                            toastr.success('@Resources.Resource.Success_PageSave');
                            return;
                        }
                        toastr.success('@Resources.Resource.Success_PageSaveAndPublish');
                        return;
                    },
                    error: function(error) {
                        toastr.error('@Resources.Resource.Error_Unexpected');
                        return;
                    },
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    beforeSend: function() {
                        waitingDialog.show('@Resources.Resource.Waiting_PageUpdating');
                    },
                    complete: function() {
                        waitingDialog.hide();
                    }
                });

在控制器中我编写了以下代码;

        [HttpPost]
        [ValidateInput(false)]
        [AppAuthorize(AccessType = AccessType.Page_Add)]
        public ActionResult Add(Page item)
        {
            if (item == null
                || string.IsNullOrEmpty(item.Title)
                || string.IsNullOrEmpty(item.SeoUrl))
                return Content(Serialization.JsonSerialize(new { Status = 400 }));

            return Content(Serialization.JsonSerialize(new { Status = 200, Result = PageRepository.Add(item) }));
        }
我在下面添加了web配置中的

;

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

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="vs:EnableBrowserLink" value="false" />
    <add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
  </appSettings>
<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <handlers>
      <remove name="BotDetectCaptchaHandler" />
      <add name="BotDetectCaptchaHandler" preCondition="integratedMode" verb="GET" path="BotDetectCaptcha.ashx" type="BotDetect.Web.CaptchaHandler, BotDetect" />
    </handlers>
  </system.webServer>

post方法返回错误。它没有达到控制器。如何在MVC项目中传递此base64字符串。

0 个答案:

没有答案