这个错误是由于在 Content Security Policy(CSP)中未找到指定的报告终点而造成的。为了解决此问题,您需要执行以下操作:
services.AddAntiforgery(options => { options.SuppressXFrameOptionsHeader = true; });
app.Use(async (context, next) => { context.Response.Headers.Add("Content-Security-Policy", "default-src 'self'; report-uri /cspreport"); await next.Invoke(); });
app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapFallbackToFile("index.html"); });
通过以上步骤,您就可以解决 Asp.net Core 中出现“Content Security Policy Endpoint cspreport not found POST https://localhost:44331/cspreport returns 404”错误了。
上一篇:ASP.NETCore中出现异常时,HttpContext.Response.StatusCode的值为200
下一篇:ASP.NETCore中出现“Thename'model,htmlviewdata'doesnotexistincurrentcontext”的错误。