在ASP.NET上创建JSON标头

时间:2009-05-21 20:02:18

标签: c# php asp.net json header

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

标题('Content-type:text / json');

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

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

2 个答案:

答案 0 :(得分:39)

Response.ContentType = "application/json";

或更一般地

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

答案 1 :(得分:5)

有关JerSchneid答案的其他信息

如果您收到如下错误消息:

  

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

您可以这样使用:

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