首页 > 解决方案 > 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>

这有什么线索吗?

标签: c#angulariisasp.net-core

解决方案


将 index.html 放在 wwwroot 文件夹中。那是应该提供静态文件的文件夹。


推荐阅读