csharp 以下代码为具有指定源的整个应用程序启用CORS:
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 以下代码为具有指定源的整个应用程序启用CORS:相关的知识,希望对你有一定的参考价值。
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
//ova linija
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
//ovaj komad
services.AddCors(options =>
{
options.AddPolicy(MyAllowSpecificOrigins,
builder =>
{
builder.WithOrigins("http://example.com",
"http://www.contoso.com")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
//ovaj komad
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
//ova linija
app.UseCors(MyAllowSpecificOrigins);
app.UseHttpsRedirection();
app.UseMvc();
}
}
以上是关于csharp 以下代码为具有指定源的整个应用程序启用CORS:的主要内容,如果未能解决你的问题,请参考以下文章