Angular 6+ASP.NET核心MVC内部服务结构

Angular 6+ASP.NET核心MVC内部服务结构,angular,asp.net-core,azure-service-fabric,Angular,Asp.net Core,Azure Service Fabric,我正在尝试运行一个“无状态ASP.NET核心”API项目,在服务结构中使用Angular 6 我做什么 创建ASP.NET核心API项目。 通过运行“ng new ClientApp”在ASP.NET核心项目中创建角度项目。 在Angular项目内运行ng build以生成文件。 编辑Startup.cs请参见下面的代码 Startup.cs 结果 !!如果我创建了一个普通的非服务结构ASP.NET核心API,那么这种方法是有效的 如果创建相同的内部服务结构,则会出现以下错误: //编辑 通过遵

我正在尝试运行一个“无状态ASP.NET核心”API项目,在服务结构中使用Angular 6

我做什么

创建ASP.NET核心API项目。 通过运行“ng new ClientApp”在ASP.NET核心项目中创建角度项目。 在Angular项目内运行ng build以生成文件。 编辑Startup.cs请参见下面的代码

Startup.cs

结果

!!如果我创建了一个普通的非服务结构ASP.NET核心API,那么这种方法是有效的

如果创建相同的内部服务结构,则会出现以下错误:

//编辑


通过遵循

解决了这个问题。通过遵循此链接中的指南,我能够使它正常工作


它是德语的,但您应该能够在Google Translate的帮助下找到它:

将此NuGet软件包添加到您的项目中:

NWebsec.AspNetCore.Middleware

并进行如下配置:

app.UseHstsh=>h.MaxAgedays:100.preload

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");
            }
        });
    }
}