Commit 3d508526 authored by liudong1993's avatar liudong1993

调整配置

parent fbf86b1b
......@@ -4,7 +4,9 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using System.Text.Unicode;
......@@ -22,26 +24,12 @@ namespace Property.WebApi
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(options =>
//{
// options.AllowSynchronousIO = true;
//});
services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(x => x.AllowSynchronousIO = true)
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文
//services.AddMvc().AddNewtonsoftJson(options =>
//{
// // 忽略循环引用
// options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
// // 不使用驼峰
// options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();//json字符串大小写原样输出
// // 设置时间格式
// options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
// // 如字段为null值,该字段不会返回到前端
// // options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
// options.SerializerSettings.Converters.
//});
services.AddMvc().AddJsonOptions(options =>
{
......@@ -49,19 +37,43 @@ namespace Property.WebApi
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
services.AddCors(options => options.AddPolicy("AllowCors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins(new[] { "http://www.test.com:8080", "http://www.test.com:8081", "http://www.test.com:8082", "http://testzcyx.oytour.com:8080", "http://testzcyx.oytour.com:8081", "http://zcyx.oytour.com", "http://yx.oytour.com" })));
//services.AddCors(options =>
//{
// options.AddPolicy("AllowCors",
// builder =>
// {
// builder.WithOrigins("http://www.test.com:8080")
// .SetIsOriginAllowedToAllowWildcardSubdomains()
// .AllowAnyHeader()
// .AllowAnyMethod()
// .AllowCredentials();
// });
//});
List<string> corsArray = GetAllowCorsList();
services.AddCors(options => options.AddPolicy("AllowCors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins(corsArray.ToArray())));
}
/// <summary>
/// 获取配置的域名管理
/// </summary>
/// <returns></returns>
private static List<string> GetAllowCorsList()
{
string accessSiteStr = new ConfigurationBuilder().Add(new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("accessSiteStr").Value;
List<string> corsArray = new List<string>()
{
"http://www.test.com:8080",
"http://www.test.com:8081",
"http://www.test.com:8082",
"http://testzcyx.oytour.com:8080",
"http://testzcyx.oytour.com:8081",
"http://testzcyx.oytour.com",
"http://testzcerp.oytour.com",
"http://zcyx.oytour.com",
"http://yx.oytour.com"
};
if (!string.IsNullOrEmpty(accessSiteStr))
{
var accesslist = accessSiteStr.Split(',');
foreach (var item in accesslist)
{
if (!string.IsNullOrEmpty(item))
{
corsArray.Add(item);
}
}
corsArray = corsArray.Distinct().ToList();
}
return corsArray;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
......@@ -30,5 +30,6 @@
"RedisServer": "192.168.2.214",
"RedisPort": "6379",
"RedisPwd": "123456"
}
},
"accessSiteStr": "http://testzcys.oytour.com,http://testzc2erp.oytour.com,http://testzc3erp.oytour.com"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment