34 lines
857 B
C#
34 lines
857 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
namespace HuanMeng.DotNetCore.CustomExtension
|
|
{
|
|
/// <summary>
|
|
/// 添加跨域
|
|
/// </summary>
|
|
public static class CorsExtension
|
|
{
|
|
/// <summary>
|
|
/// 添加跨域
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="policyName"></param>
|
|
public static void AddCustomCors(this IServiceCollection services, string policyName)
|
|
{
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(policyName,
|
|
builder =>
|
|
{
|
|
builder
|
|
.AllowAnyOrigin()
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod();
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
}
|