【问题标题】:angular 2 app publish not working on .net hostingangular 2 app publish 在.net 主机上不起作用
【发布时间】:2018-01-09 20:19:54
【问题描述】:

您好,我正在尝试将我的 Angular 4 应用程序发布到我的 .net 服务器

我做了 ng build,我得到了 dist 文件

然后我将 dist 文件中的文件发布到我的 ftp 根文件夹 (httpdocs)

当我发布并打开网站时,我在控制台上收到此错误

/inline.bundle.js Failed to load resource: net::ERR_CONNECTION_RESET
/polyfills.bundle.js Failed to load resource: net::ERR_CONNECTION_RESET
/styles.bundle.js Failed to load resource: net::ERR_CONNECTION_RESET
/scripts.bundle.js Failed to load resource: net::ERR_CONNECTION_RESET
/vendor.bundle.js Failed to load resource: net::ERR_CONNECTION_RESET
/main.bundle.js Failed to load resource: net::ERR_CONNECTION_RESET

我尝试在 index.html 文件中将 base href 从 = '/' 替换为 ' ' 但没有成功

我到底应该怎么想?

我的 index.html 文件

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Ne Nerede ?</title>
  <base href="">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="oneriyorum.ico">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <link rel="stylesheet" href="node_modules/ladda/dist/ladda.min.css">
  <script>

  </script>
</head>
<body class="hold-transition login-page">
<app-root></app-root>
<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="scripts.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
</body>
</html>

【问题讨论】:

  • 检查您的标签“脚本”是否像 而不是
  • 我编辑了我的问题你可以看到 index.html 文件

标签: .net angular publish


【解决方案1】:

基本上你唯一要做的就是

1.-新建项目Web API,Core 2.0为空 2.-修改startup.cs的函数Configure,增加UseDefaultFiles和useStaticFiles

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    app.UseDefaultFiles();
    app.UseStaticFiles();
}

2.-将你的“dist”文件夹复制到 wwwroot

3.-你的 index.html 会是这样的

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>MyApp</title>
    <base href="/">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link href="styles.e85e86d6d65752737800.bundle.css" rel="stylesheet" />
</head>
<body>
    <app-root>Loading..</app-root>
    <script type="text/javascript" src="inline.1aea26911fb58219f5a8.bundle.js"></script>
    <script type="text/javascript" src="polyfills.ad37cd45a71cb38eee76.bundle.js"></script>
    <script type="text/javascript" src="main.d1e85e225566be5f9e29.bundle.js"></script>
</body>
</html>

4.-发布您的项目

(您在www.codeproject.com 中查看此链接以获得更完整的答案)

【讨论】:

  • 创建 c# 项目并包含我的 Angular 项目的唯一方法?
  • 您可以尝试将 index.html 中的“基本标签”替换为 document.write('');。我不确定在这种情况下您是否必须使用主题标签策略
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多