c# - index.html 未在 Angular2 中部署
问题描述
我创建了一个以 Angular2 作为前端的 ASP.Net Core 项目。
我已将 index.html 文件放在 UI 项目的主文件夹中,当我编译和发布项目时,它没有被部署到发布文件夹。下面是我用过的代码Startup.cs
app.Use(async (context, next) => {
await next();
if (context.Response.StatusCode == 404 &&
!Path.HasExtension(context.Request.Path.Value) &&
!context.Request.Path.Value.StartsWith("/api"))
{
context.Request.Path = "/index.html";
await next();
}
});
当我尝试直接从 IIS 访问文件时,它说找不到。
应用网址是http://localhost:81/
bs-config.json的内容如下
{
"server": {
"baseDir": "./dist",
"routes": {
"/node_modules": "node_modules"
}
}
}
但是项目中没有 ./dist 文件夹。
这是 index.html 文件的内容
<!DOCTYPE html>
<html>
<head>
<title>Node Junction</title>
<base href="http://localhost:81">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="src/styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="src/systemjs.config.js"></script>
<script>
System.import('main.js').catch(function (err) { console.error(err); });
</script>
</head>
<body>
<my-app>Loading AppComponent content here ...</my-app>
</body>
</html>
这有什么线索吗?
解决方案
将 index.html 放在 wwwroot 文件夹中。那是应该提供静态文件的文件夹。
推荐阅读
- javascript - 如何对 luxon 对象数组执行排序
- azure-virtual-network - Azure 虚拟网络子网连接问题
- python - Python BeautifulSoup 网址
- react-native - 世博隧道不工作(无效证书)
- python - 有没有更 Pythonic 的方式来创建具有内存的系列
- netcdf - 如何使用 xarray 将投影信息写入 netcdf 文件?
- c++ - “超出 PCH 的虚拟范围”问题 - 在 Visual Studio 2019 升级到 16.7.6 之后
- makefile - makefile 中的引号
- java - recylerview适配器中的getItemcount方法
- ios - xcode 12 中的 GADUnifiedNativeAdView 中缺少 IBOutlets