我开发了一个asp.net core 2.0 MVC应用程序,增加了一个Angular 6前端应用程序.它们都存在于同一个项目结构中.asp.net核心应用程序充当客户端Angular 6应用程序的API.
我一直在开发它们,并在Startup.cs文件中包含以下代码段,以便在两个应用程序运行时进行开发:
ConfigureServices
services.AddSpaStaticFiles(configuration => {
configuration.RootPath = "ClientApp/dist";
});
Configure
app.UseSpa(spa => {
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment()) {
spa.UseAngularCliServer(npmScript: "start");
}
});
Run Code Online (Sandbox Code Playgroud)
可以在ClientApp中找到Angular应用程序的项目结构.
我知道希望将此项目部署到IIS.所以我正在离开开发环境,所以我知道代码行:spa.UseAngularCliServer(npmScript: "start");不会运行.
当我通过Visual Studio发布项目并将其移动到inetpub文件夹时,就像我为其他应用程序所做的那样,它不会为我在Angular 6应用程序中开发的页面提供服务.尝试访问我在Angular 6应用程序的RoutingModule中定义的/ Home这样的页面时出现500内部服务器错误.
我假设这是因为我需要构建Angular应用程序(我可以完成ng build --prod)并将已编译的JS文件添加到HTML页面.但我不确定如何解决这个问题.如果有人有任何链接到相关的网页,将不胜感激.或者,如果您能提供任何非常有用的见解.
更新#1:
在Startup.cs文件中,我使app.UseDeveloperExceptionPage()在生产模式下运行时可用.
而不是500内部服务器错误页面,我得到了例外: SPA默认页面中间件无法返回默认页面'/index.html',因为找不到它,并且没有其他中间件处理该请求.
我还注意到发布后ClientApp/dist文件夹不存在.我手动构建ClientApp并将其添加到inetpub中的应用程序.现在,我在控制台中收到错误:
runtime.a66f828dca56eeb90e02.js:1 Uncaught SyntaxError: Unexpected token <
polyfills.7a0e6866a34e280f48e7.js:1 Uncaught SyntaxError: Unexpected token <
Request:10 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/styles.169e0a841442606822c8.css".
scripts.ee7fed27c36eaa5fa8a9.js:1 Uncaught SyntaxError: Unexpected token …Run Code Online (Sandbox Code Playgroud)