在ASP.NET上创建JSON标头

17 php c# asp.net json header

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

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

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

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

Jer*_*eid 40

Response.ContentType = "application/json";
Run Code Online (Sandbox Code Playgroud)

或更一般地说

Response.Headers.Add("Content-type", "text/json");
Response.Headers.Add("Content-type", "application/json");
Run Code Online (Sandbox Code Playgroud)


dvd*_*dmn 5

关于JerSchneid的答案的其他信息

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

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

你可以这样使用:

Response.AddHeader("Content-type", "text/json");
Run Code Online (Sandbox Code Playgroud)