41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Learn.VideoAnalysis.Expand
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static class CorsExpand
|
|
{
|
|
/// <summary>
|
|
/// 添加跨域拓展
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
public static void AddCorsExpand(this IServiceCollection services)
|
|
{
|
|
services.AddCors(c =>
|
|
{
|
|
c.AddPolicy("All", policy =>
|
|
{
|
|
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
|
|
});
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 使用跨域
|
|
/// </summary>
|
|
/// <param name="app"></param>
|
|
public static void UseCorsExpand(this WebApplication app)
|
|
{
|
|
app.UseCors("All");
|
|
// 获取配置文件中的允许跨域的地址
|
|
app.UseCors(options =>
|
|
{
|
|
options.WithOrigins("*") // 允许跨域请求的地址
|
|
.AllowAnyHeader() // 允许的请求标头
|
|
.AllowAnyMethod(); // 允许跨域请求的类型 (GET,POST等)
|
|
});
|
|
}
|
|
}
|
|
} |