[英]How to set Content-Type for a Redirect in ASP.NET Core MVC controller
I'm trying to redirect to an external page that accepts application/json content-type using我正在尝试使用重定向到接受 application/json 内容类型的外部页面
return RedirectPermanent(url);
I couldn't find a way to set the cotent-type on RedirectResult but looks like ContentResult
could be used this way我找不到在 RedirectResult 上设置 cotent-type 的方法,但看起来ContentResult
可以这样使用
var contentResult = new ContentResult();
contentResult.ContentType = "application/json";
contentResult.StatusCode = (int)HttpStatusCode.MovedPermanently;
return contentResult;
How can I set the URL in the ContentResult
or set the content-type in RedirectResult?如何在ContentResult
中设置 URL 或在 RedirectResult 中设置 content-type?
Setting the URL on Response like this worked像这样在响应上设置 URL 有效
public ActionResult Endpoint()
{
Response.Redirect(url);
var contentResult = new ContentResult();
contentResult.ContentType = "application/json";
contentResult.StatusCode = (int)HttpStatusCode.MovedPermanently;
return contentResult;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.