通过IActionFilter的ASP.NET Core设置Response.ContentType结果为406不允许

我正在使用IactionFilter.OnactionExecuted(ASP.NET Core 3.1)设置具有媒体类型和字符集的context.HttpContext.response.contenttype,例如application / json; charset = utf-8。

但是,当设置ContentType属性时,将返回响应状态代码406 Not allow。

我尝试过:

  • 设置请求的accept标头(accept:application / json; accept-Charset:utf-8);
  • services.AddMvc(options => options.RespectBrowseracceptheader = false);
  • services.AddMvc(options => options.ReturnHttpNotacceptable = true);

加上上述各项的组合,但406不断返回。

然后我尝试设置不带字符集的响应内容类型,并且有效!!

这可能有意义,因为accept = application / json!= Content-Type = application / json; charset = utf-8,但是现在找不到设置字符集的方法。

有什么想法吗?

干杯

彼得

iCMS 回答:通过IActionFilter的ASP.NET Core设置Response.ContentType结果为406不允许

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2020036.html

大家都在问