admin管理员组文章数量:1287517
I have a controller with a method which should only output static JSON content to the browser. E.g.
public async Task<ActionResult> Test()
{
return Content("{ \"key\": \"value\" }", "application/json");
}
This works fine when I debug locally via Visual Studio, however, after deployed on IIS the response is just blank.
So feels like some configuration on the IIS that needs to be done?
Does anyone have any idea?
I have a controller with a method which should only output static JSON content to the browser. E.g.
public async Task<ActionResult> Test()
{
return Content("{ \"key\": \"value\" }", "application/json");
}
This works fine when I debug locally via Visual Studio, however, after deployed on IIS the response is just blank.
So feels like some configuration on the IIS that needs to be done?
Does anyone have any idea?
Share Improve this question edited Feb 24 at 14:12 Uwe Keim 40.7k61 gold badges188 silver badges303 bronze badges asked Feb 24 at 9:28 NikksterNikkster 3372 silver badges13 bronze badges 4 |2 Answers
Reset to default 1Did you try using JsonResult instead?
public async Task<JsonResult> Test()
{
return new JsonResult()
{
Data = new { key = "value" },
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
I managed to solve this by adding the following to <system.webServer> tag in Web.config;
<httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough">
</httpErrors>
本文标签: cReturn content is quotblankquot when deployed on productionStack Overflow
版权声明:本文标题:c# - Return content is "blank" when deployed on production - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741282320a2370077.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
return new { key = "value" };
(or use a Model class or DTO class) and letting the MVC API Controller machinery do the serializing + setting the response type. – Peter B Commented Feb 24 at 9:55