【发布时间】:2021-10-06 14:20:38
【问题描述】:
我已经构建了我的 Angular 应用程序,输出是我的 ASP .NET API 文件夹中的 wwwroot 文件夹。 当我使用 dotnet watch run 构建应用程序时,一切正常并显示正常,但是当我刷新路由 localhost:5000/users 时,它显示的是原始 json 文件而不是 HTML/CSS 内容
控制台错误显示以下消息:内容安全策略:页面的设置阻止在 https://localhost:5000/favicon.ico (“default-src”) 加载资源;
在网络引用策略中说“strict-origin-when-cross-origin”,但我的 cors 设置为 app.UseCors(x=>x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
我的端点
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToController("Index","Fallback");
});
后备控制器
public class FallbackController : Controller
{
public IActionResult Index(){
return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(),"wwwroot","index.html"),
"text/HTML");
}
}
来自 wwwroot 文件夹的 Index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SocialNetworkSPA</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
我的 ASP .NET Core 版本是 3.1 和 Angular 11
请不要在我刷新页面之前一切都正常工作,然后出现这些错误
【问题讨论】:
标签: asp.net angular asp.net-core asp.net-web-api build