42 lines
937 B
C#
42 lines
937 B
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Common.Cors
|
|
{
|
|
|
|
public static class CorsExtension
|
|
{
|
|
public static IServiceCollection AddCustomCors(this IServiceCollection services)
|
|
{
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("Cors", policy =>
|
|
{
|
|
policy
|
|
|
|
.SetIsOriginAllowed(_ => true)
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials()
|
|
;
|
|
|
|
|
|
});
|
|
});
|
|
|
|
return services;
|
|
}
|
|
|
|
|
|
public static void UseCustomCors(this IApplicationBuilder app)
|
|
{
|
|
app.UseCors("Cors");
|
|
}
|
|
}
|
|
}
|