【问题标题】:c# Response.Write and End() Json String to longc# Response.Write and End() Json String to long
【发布时间】:2016-12-20 13:49:47
【问题描述】:

当我将此文件保存在磁盘上时,我试图输出一个“非常长”的 Json 字符串,它是 405KB,但我想通过 Response.Write 将它提供给客户端,但由于某些奇怪的原因并没有输出字符串已填充。 这是一个没有 MVC 的简单 ASP.NET 网页 当我使用

    // Clear out the buffer
    Response.ClearHeaders();
    Response.ClearContent();
    Response.Clear();

    // Do not cache response
    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    // Set the content type and encoding for JSON
    Response.ContentType = "application/json";
    Response.ContentEncoding = Encoding.UTF8;
    Response.Write(strJsonData);

    // Flush the response buffer
    Response.Flush();

    // Complete the request.  NOTE: Do not use Response.End() here,
    // because it throws a ThreadAbortException, which cannot be caught!
    HttpContext.Current.ApplicationInstance.CompleteRequest();

它不会在我的屏幕上显示响应。

我尝试了什么: 网页配置

<httpRuntime maxRequestLength ="999999999" requestValidationMode="2.0" />

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="999999999" />
        </requestFiltering>
    </security>
</system.webServer>

【问题讨论】:

  • 错误信息是什么? Response.Write 是关于传出,requestLimits 是关于传入数据
  • ondisk 是什么意思?那你想把字符串保存在服务器上吗?还是说你真的是想给客户端发送一个 Json 结果?
  • 我的意思是当我将文件保存在磁盘上 405kb 时文件本身是但我想用 Response.Write 向客户端响应它但它不起作用但 JsonResult 已填充。
  • 这是什么网站? Web 表单,MVC? JsonResult 是什么?是你的字符串的名字吗?它有内容吗?你是怎么填的?
  • Exaclty fubo 但字符串中填充了正确的序列化 JSON 数据

标签: c# asp.net json webforms


【解决方案1】:

请求长度限制发送到服务器的请求长度,而不是响应。

在 Web.config 中试试这个:

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

【讨论】:

  • 我去试试
猜你喜欢
  • 2022-12-02
  • 1970-01-01
  • 2014-04-10
  • 2022-12-19
  • 2015-01-07
  • 2022-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多