我正在尝试使用Service Fabric中的Angular 6运行'无状态ASP.NET核心'API项目。
我做什么
编辑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中创建相同的内容,我会收到以下错误:
// EDIT
解决问题答案 0 :(得分:1)
我可以按照此链接中的指南https://blog.bridging-it.de/blog/blogeintrag_4480.html
开始工作它位于德语中,但您应该能够在Google翻译的帮助下弄明白:)
答案 1 :(得分:0)
将此NuGet软件包添加到您的项目中:
NWebsec.AspNetCore.Middleware
并配置如下内容:
app.UseHsts(h=> h.MaxAge(days:100).preload())