【发布时间】:2018-11-18 12:25:01
【问题描述】:
我正在尝试在 Service Fabric 中使用 Angular 6 运行“无状态 ASP.NET Core”API 项目。
我做什么
- 创建 ASP.NET Core API 项目。
- 通过运行 'ng new ClientApp 在 ASP.NET Core 项目中创建一个 Angular 项目。
- 在 Angular 项目中运行 ng build 以生成文件。
-
编辑 Startup.cs(见下面的代码)
Startup.cs
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); } }
结果
!!如果我创建一个普通的(非 Service Fabric)ASP.NET Core API,这种方法就有效。 !!
如果我在 Service Fabric 中创建相同的内容,我会收到以下错误:
//编辑
【问题讨论】:
标签: angular asp.net-core azure-service-fabric