Answers for "asp.net allow cors for all"

C#
2

asp.net allow cors for all

// Credit_1: https://www.infoworld.com/article/3327562/how-to-enable-cors-in-aspnet-core.html
// Credit_2: https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0

// At class "Startup":
#region global variables
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
#endregion

// Inside "ConfigureServices" function
// From a --SINGLE SOURCE-- (in this case localhost:4200):
services.AddCors(options =>
{
	options.AddPolicy(name: MyAllowSpecificOrigins,
	builder => builder.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader());
});

// From --ALL SOURCES--:
services.AddCors(options =>
{
	options.AddPolicy(name: MyAllowSpecificOrigins,
    builder => builder.AllowAnyOrigin());
});

// Inside "Configure" function
app.UseCors(MyAllowSpecificOrigins);
Posted by: Guest on August-03-2021
0

enable cors asp.net mvc

public static void Register(HttpConfiguration config)
{
    var corsAttr = new EnableCorsAttribute("http://example.com", "*", "*");
    config.EnableCors(corsAttr);
}
Posted by: Guest on October-04-2020
0

enable cors asp.net mvc

public static void Register(HttpConfiguration config)
{
    // New code
    config.EnableCors();
}
Posted by: Guest on October-04-2020
0

enable cors asp.net mvc

Response.AppendHeader("Access-Control-Allow-Origin", "*");
Posted by: Guest on October-04-2020

C# Answers by Framework

Browse Popular Code Answers by Language