Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to enable cors .net

/* default policy */

// add policy
builder.Services.AddCors(options =>
{
	options.AddDefaultPolicy(policy =>
    {
    	policy.WithOrigins("http://localhost:4200") // or AllowAnyOrigin()
        .AllowAnyHeader()
        .AllowAnyMethod()
        .AllowAnyOrigin();
    })
});

// enable policy
app.UseCors();

/* named policy */

// add policy
var AllowWebClient = "allowWebClient";
builder.Services.AddCors(options =>
{
    options.AddPolicy(name: AllowWebClient,
    	policy => 
        {
          policy.WithOrigins("http://localhost:4200") // or AllowAnyOrigin()
          .AllowAnyHeader()
          .AllowAnyMethod()
          .AllowAnyOrigin();
        }
    );
});

// enable policy
app.UseCors(AllowWebClient);
Comment

enable cors asp.net mvc

public static void Register(HttpConfiguration config)
{
    var corsAttr = new EnableCorsAttribute("http://example.com", "*", "*");
    config.EnableCors(corsAttr);
}
Comment

enable cors asp.net mvc

public static void Register(HttpConfiguration config)
{
    // New code
    config.EnableCors();
}
Comment

To enable CORS in the MVC Java config

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/api/**")
            .allowedOrigins("https://domain2.com")
            .allowedMethods("PUT", "DELETE")
            .allowedHeaders("header1", "header2", "header3")
            .exposedHeaders("header1", "header2")
            .allowCredentials(true).maxAge(3600);

        // Add more mappings...
    }
}
Comment

enable cors asp.net mvc

Response.AppendHeader("Access-Control-Allow-Origin", "*");
Comment

PREVIOUS NEXT
Code Example
Csharp :: new datetime c# 
Csharp :: XMLWriter write xml C# 
Csharp :: window height in C# forms 
Csharp :: using in c# 
Csharp :: c# datetime remove days 
Csharp :: unity initialize array 
Csharp :: microsoft forms create bitmap 
Csharp :: string in c# 
Csharp :: c# callback action lambda 
Csharp :: visitor pattern 
Csharp :: dynamically add rows to datagridview c# 
Csharp :: registry keys and values 
Csharp :: Disable Debug.log Unity 
Csharp :: get mouse inpuit new input system 
Csharp :: edit list element linq c# 
Csharp :: How to use the protected keyword in C# 
Csharp :: Get Mac address of Device in Xamarin 
Csharp :: open linkedlabel c# 
Csharp :: IsInstanceOf nunit 
Csharp :: how to do that a objetct moves in c# 
Csharp :: scene manager load scene 
Csharp :: winform fixed size 
Csharp :: c# calculate checksum of file 
Csharp :: c# int to string date conversion 
Csharp :: c# split quotation 
Csharp :: unity get distance between line and point 
Csharp :: You can get events when an object is visible within a certain camera, and when it enters or leaves, using these functions: 
Csharp :: cursor position c# 
Csharp :: .net core copy file in folder to root 
Csharp :: faucongz 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =