我有一个内容安全策略导致 Chrome 发布报告,但接收报告的操作返回“415 不支持的媒体类型”。我理解这是因为该帖子的 Content-Type 为“application/csp-report”。我如何将其添加为 Core 3.1 中允许的内容类型(它基本上只是 json)。
行动
// https://anthonychu.ca/post/aspnet-core-csp/
[HttpPost][Consumes("application/csp-report")]
public IActionResult Report([FromBody] CspReportRequest request)
{
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
模型的缩减版本
public class CspReportRequest
{
[JsonProperty(PropertyName = "csp-report")]
public CspReport CspReport { get; set; }
}
public class CspReport
{
[JsonProperty(PropertyName = "document-uri")]
public string DocumentUri { get; set; }
}
Run Code Online (Sandbox Code Playgroud)