【问题标题】:Limit of 88 bytes on response.write?response.write 的 88 字节限制?
【发布时间】:2012-12-01 21:48:21
【问题描述】:

我正在尝试从 wcf 服务提供一个 csv 文件,作为字符串响应。

看起来像这样:

HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=ImportErrors.csv");
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.Write(myCsvContent);

响应 StatusCode 设置为 (int)HttpStatusCode.OK (200)

它可以工作,但我只得到 88 个字节的 csv,其余部分被截断(未显示)。

关于去哪里看有什么建议吗?我在 web.config 中没有看到任何设置限制的自定义条目。

【问题讨论】:

    标签: .net wcf csv response.write contenttype


    【解决方案1】:

    一定要打电话

    HttpContext.Current.Response.Flush();
    HttpContext.ApplicationInstance.CompleteRequest();
    

    这将关闭流并刷新其余内容。

    编辑:查看this link。看来我原来的资料有点过时了……我在“MVC Land”里呆了这么久都忘记了这个模式!

    【讨论】:

    • Response.End() 在服务方法中为我抛出异常,堆栈跟踪不会让我看到究竟是什么问题 - 我怀疑因为这会阻止返回合同期望的任何返回类型。但是,您的回答无论如何都解决了我的问题,因为您提到了刷新内容。在每行之后执行 Response.Flush() 不会引发异常,而是允许所有数据遇到。
    • 谢谢。帖子已编辑。由于某种原因,我永远不记得您是否需要在之前调用 Flush()。关于“为什么”有时没有足够的文档......
    • 我很惊讶。除了 ajax-comet 样式的响应之外,永远不需要刷新...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多