angular 2 app publish not working on .net hosting

余生颓废 提交于 2019-12-24 20:49:37

问题


Hello i'm trying to publish my angular 4 app to my .net server

i did ng build and i got dist file

then i publish my files that inside the dist file to my ftp root folder ( httpdocs )

when i publish and open web site i get this error on console

/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

i tried in index.html file replacing base href from = '/' to ' ' but it didnt work

what exactly should i what do you think ?

my index.html file

<!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>

回答1:


Basically the only thing you have to make are

1.-Create a new project Web API, Core 2.0 empty 2.-Change the function Configure of startup.cs, adding UseDefaultFiles and useStaticFiles

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

2.-Copy your "dist" folder in wwwroot

3.-Your index.html will be like

<!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.-Publish your project

(you check this link in www.codeproject.com for more complet answer)



来源:https://stackoverflow.com/questions/48176085/angular-2-app-publish-not-working-on-net-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!