現在、私はCSPヘッダーを実装するためにNWebsec.AspNetCore.Middleware Nugetパッケージを使用しています。単純に新しいASP.NET Core 1.1 MVCアプリケーションを作成し、それに続いて起動を変更すると、コンソールからスクリプトを挿入することは可能です。私は何が欠けていますか?ASP.Net Core 1.1 - Angular2プロジェクトCSPが動作しない
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseCsp(csp =>
{
csp.DefaultSources(src => src.Self());
});
}
}
Angular2で生成された静的ファイル(WebPack)にCSPセキュリティを設定します。しかし、CSPは適用されていないようです。