1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| using JiepeiWMS.Common;
| using Microsoft.Extensions.DependencyInjection;
| using System;
|
| namespace JiepeiWMS.Extensions
| {
| /// <summary>
| /// Cors 启动服务
| /// </summary>
| public static class CorsSetup
| {
| public static void AddCorsSetup(this IServiceCollection services)
| {
| if (services == null) throw new ArgumentNullException(nameof(services));
|
| services.AddCors(c =>
| {
| if (!Appsettings.app(new string[] { "Startup", "Cors", "EnableAllIPs" }).ObjToBool())
| {
| c.AddPolicy(Appsettings.app(new string[] { "Startup", "Cors", "PolicyName" }),
|
| policy =>
| {
|
| policy
| .WithOrigins(Appsettings.app(new string[] { "Startup", "Cors", "IPs" }).Split(','))
| .AllowAnyHeader()//Ensures that the policy allows any header.
| .AllowAnyMethod();
| });
| }
| else
| {
| //允许任意跨域请求
| c.AddPolicy(Appsettings.app(new string[] { "Startup", "Cors", "PolicyName" }),
| policy =>
| {
| policy
| .AllowAnyOrigin()
| .AllowAnyMethod()
| .AllowAnyHeader();
| });
| }
|
| });
| }
| }
| }
|
|