小编Bri*_*ian的帖子

ASP.NET Core 中内容类型“application/csp-report”的“415 Unsupported Media Type”

我有一个内容安全策略导致 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)

c# asp.net-core asp.net-core-3.1

9
推荐指数
2
解决办法
1642
查看次数

标签 统计

asp.net-core ×1

asp.net-core-3.1 ×1

c# ×1