【发布时间】:2016-07-08 17:21:55
【问题描述】:
在开发 ASP.NET MVC 4 应用程序期间,我在控制器操作中遇到了以 JSON 格式返回通知的问题。下面我附上了我用来发送通知的代码:
return GetNotificationResult(HttpStatusCode.BadRequest, notification);
private JsonResult GetNotificationResult(HttpStatusCode code, string notification)
{
Response.StatusCode = (int) code;
return Json(new { Notification = notification });
}
当我在 localhost 上测试它时,它按预期工作(它返回状态代码 BadRequest 并且正文包含带有通知的 JSON)。
但是,当我在 Azure 中将此代码部署为 Web 应用程序时,它只返回 BadRequest 而没有 JSON 通知。
在云和本地主机上调用此代码时,什么会导致不同的结果?
【问题讨论】:
-
尝试将此添加到您的
web.config:<system.webServer> <httpErrors existingResponse="PassThrough"/> </system.webServer> -
@Igor 成功了。谢谢!
-
好交易。我把它写在下面作为答案,如果它有帮助,请使用它旁边的复选框标记它。
标签: asp.net json asp.net-mvc