Service Fabric

时间:2018-06-08 12:28:27

标签: angular asp.net-core azure-service-fabric

我正在尝试使用Service Fabric中的Angular 6运行'无状态ASP.NET核心'API项目。

我做什么

  • 创建ASP.NET Core API项目。
  • 通过运行“ng new ClientApp。
  • 在ASP.NET Core项目中创建一个Angular项目
  • 在Angular项目中运行构建以生成文件。
  • 编辑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中创建相同的内容,我会收到以下错误:

enter image description here

// EDIT

按照https://blog.bridging-it.de/blog/blogeintrag_4480.html

解决问题

2 个答案:

答案 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())