Last active
September 12, 2021 11:41
-
-
Save mirmostafa/0d11b8f54484f002b5106e0085451896 to your computer and use it in GitHub Desktop.
Solve CORS Origin Problem: Server-side
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [EnableCors("AllowOrigin")] | |
| public class SecurityController : Controller | |
| { | |
| //.... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) | |
| { | |
| //.... | |
| app.UseCors("AllowAnyOrigin"); | |
| app.UseCors("AllowOrigin"); | |
| app.UseCors("CorsPolicy"); | |
| app.UseCors(builder => builder | |
| //.AllowAnyOrigin() | |
| .SetIsOriginAllowed(origin => true) | |
| .AllowAnyMethod() | |
| .AllowAnyHeader() | |
| .AllowCredentials()); | |
| //.... | |
| } | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| //.... | |
| services.AddCors(options => | |
| { | |
| options.AddPolicy("AllowAnyOrigin", builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); | |
| options.AddPolicy("AllowOrigin", builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); | |
| options.AddPolicy("CorsPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials()); | |
| }); | |
| //.... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment