问题描述
您好,我正在尝试将我的 angular 4 应用程序发布到我的 .net 服务器
Hello i'm trying to publish my angular 4 app to my .net server
我做了 ng build 并得到了 dist 文件
i did ng build and i got dist file
然后我将 dist 文件中的文件发布到我的 ftp 根文件夹(httpdocs)
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
我尝试在 index.html 文件中将 base href 从 = '/' 替换为 ' ' 但没有用
i tried in index.html file replacing base href from = '/' to ' ' but it didnt work
我到底应该怎么想?
我的 index.html 文件
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>
推荐答案
基本上你唯一要做的就是
Basically the only thing you have to make are
1.-新建项目Web API,Core 2.0为空2.-更改startup.cs的Configure函数,增加UseDefaultFiles和useStaticFiles
1.-Create a new project Web API, Core 2.0 empty2.-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.-复制您在 wwwroot 中的dist"文件夹
2.-Copy your "dist" folder in wwwroot
3.-你的 index.html 会像
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.-发布您的项目
(您在 www.codeproject.com 以获得更完整的答案)
(you check this link in www.codeproject.com for more complet answer)
这篇关于angular 2 应用程序发布不适用于 .net 托管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!