5
我發現這個網站: https://docs.microsoft.com/en-us/aspnet/core/security/cors如何使全球在asp.net網頁API核心CORS
但是我如何在全球範圍內啓用它困惑,因爲它似乎有2種方式來做到這一點,請告訴我這兩種方式有何區別?或者他們做了2件不同的事情?
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)
{
//https://docs.microsoft.com/en-us/aspnet/core/security/cors
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder => builder.WithOrigins("http://example.com")
.AllowAnyHeader()
);
});
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new CorsAuthorizationFilterFactory("AllowSpecificOrigin"));
});
// 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();
app.UseCors("AllowSpecificOrigin");
app.UseMvc();
}
爲了清晰起見,Luis可以將你的代碼塊分成兩種方式嗎? – ahsteele
爲什麼你標記唯一的答案是正確的,然後給它一個賞金**尋找來自可信和/或官方消息來源的答案。**? –
這是一個錯誤,但我沒有看到如何解決它。我怎樣才能刪除賞金? –