29 lines
963 B
C#
29 lines
963 B
C#
namespace AI.Api.WebCore
|
|
{
|
|
/// <summary>
|
|
/// 跨域配置扩展服务
|
|
/// </summary>
|
|
public static class CorsAppBuilderExtensions
|
|
{
|
|
/// <summary>
|
|
/// 允许所有跨域请求 (属于基础服务,若已调用 UseBasicServices 则无需调用)
|
|
/// </summary>
|
|
/// <param name="app"></param>
|
|
/// <returns></returns>
|
|
public static IApplicationBuilder UseCustomCors(this IApplicationBuilder app)
|
|
{
|
|
//// 获取配置文件中的允许跨域的地址
|
|
//var hosts = AppSetting.AllowedHosts.Split("|", StringSplitOptions.RemoveEmptyEntries);
|
|
app.UseCors(options =>
|
|
{
|
|
options.AllowAnyOrigin() // 允许跨域请求的地址
|
|
.AllowAnyHeader() // 允许的请求标头
|
|
.AllowAnyMethod(); // 允许跨域请求的类型 (GET,POST等)
|
|
|
|
});
|
|
|
|
return app;
|
|
}
|
|
}
|
|
}
|