LoginSignup
2
1

More than 5 years have passed since last update.

asp.net core で Cross-Originの設定を行う

Last updated at Posted at 2019-03-16

asp.net

Microsoft.AspNetCore.Cors

image

Startup.cs

add services.AddCors();

public void ConfigureServices(IServiceCollection services)
{
    services.AddCors();
}

add app.UseCors

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{

    app.UseCors(builder => builder
        .AllowAnyOrigin()
        .AllowAnyMethod()
        .AllowAnyHeader()
        .AllowCredentials());

    app.UseCors(
        options => options.WithOrigins("http://example.com").AllowAnyMethod()
    );

    app.UseMvc();
}

Enabling CORS in ASP.net Core - .NET Core Tutorials

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1