在ASP.NET上创建JSON标头

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

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

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

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

Response.ContentType = "application/json"; 

或更一般地说

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

关于JerSchneid的答案的其他信息

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

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

你可以这样使用:

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