Created
March 8, 2022 15:47
-
-
Save awswithdotnet/6d02d7f4e6e6a16ebd9881eb94b99f72 to your computer and use it in GitHub Desktop.
cors Startup UseService
This file contains 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 static void UseService(IApplicationBuilder app, IConfiguration configuration) | |
{ | |
bool enableCors = bool.Parse(configuration["cors:enabled"] ?? "false"); | |
bool allowAnyOrigin = bool.Parse(configuration["cors:allowAnyOrigin"] ?? "false"); | |
if (enableCors) | |
{ | |
if (allowAnyOrigin) | |
{ | |
app.UseCors("AllowAnyOrigin"); | |
} | |
else | |
{ | |
app.UseCors("AllowSpecificOrigins"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment