Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Property
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liudong1993
Property
Commits
3d508526
Commit
3d508526
authored
Apr 23, 2020
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整配置
parent
fbf86b1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
30 deletions
+43
-30
Startup.cs
Property.WebApi/Startup.cs
+41
-29
appsettings.json
Property.WebApi/appsettings.json
+2
-1
No files found.
Property.WebApi/Startup.cs
View file @
3d508526
...
...
@@ -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.
...
...
Property.WebApi/appsettings.json
View file @
3d508526
...
...
@@ -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"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment