【问题标题】:Creating a JSON Header on ASP.NET在 ASP.NET 上创建 JSON 标头
【发布时间】:2010-10-28 01:07:11
【问题描述】:

我正在将脚本从 PHP 转换为 ASP.net C#。在 PHP 中,我可以使用类似的东西:

header('Content-type: text/json');

header('Content-type: application/json');

如何告诉我的 aspx 页面在标题中声明它正在打印 JSON 文件?

【问题讨论】:

    标签: c# php asp.net json header


    【解决方案1】:
    Response.ContentType = "application/json";
    

    或更一般地

    Response.Headers.Add("Content-type", "text/json");
    Response.Headers.Add("Content-type", "application/json");
    

    【讨论】:

    • 错误“此操作需要 IIS 集成管道模式。”无论如何要在不实际启用此模式的情况下解决这个问题?
    【解决方案2】:

    有关 JerSchneid 答案的其他信息

    如果您收到这样的错误消息:

    此操作需要 IIS 集成管道模式。

    你可以这样使用:

    Response.AddHeader("Content-type", "text/json");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 2016-06-07
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多