Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
ApiSys
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
zxw
ApiSys
Commits
62cbc6ad
Commit
62cbc6ad
authored
Mar 16, 2023
by
zxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复编码到utf8
parent
bffd18e3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
11 行增加
和
11 行删除
+11
-11
Startup.cs
ApiSys/Startup.cs
+11
-11
没有找到文件。
ApiSys/Startup.cs
View file @
62cbc6ad
...
@@ -44,16 +44,16 @@ namespace ApiSys
...
@@ -44,16 +44,16 @@ namespace ApiSys
{
{
var
connection
=
Configuration
.
GetConnectionString
(
"ConnectionStr"
);
var
connection
=
Configuration
.
GetConnectionString
(
"ConnectionStr"
);
//
读取网站配置并注入
//
读取网站配置并注入
WebInfo
webInfo
=
new
WebInfo
();
WebInfo
webInfo
=
new
WebInfo
();
//
注入验证码策略
//
注入验证码策略
services
.
AddSingleton
<
IVerCodePolicy
,
VerCodePolicy
>();
services
.
AddSingleton
<
IVerCodePolicy
,
VerCodePolicy
>();
services
.
Configure
<
WebInfo
>(
Configuration
.
GetSection
(
"WebInfo"
));
services
.
Configure
<
WebInfo
>(
Configuration
.
GetSection
(
"WebInfo"
));
Configuration
.
GetSection
(
"WebInfo"
).
Bind
(
webInfo
);
Configuration
.
GetSection
(
"WebInfo"
).
Bind
(
webInfo
);
services
.
AddSingleton
(
webInfo
);
services
.
AddSingleton
(
webInfo
);
services
.
AddRazorPages
().
AddRazorRuntimeCompilation
();
services
.
AddRazorPages
().
AddRazorRuntimeCompilation
();
services
.
AddTransient
(
typeof
(
UnitOfWork
));
//
注入工作单元
services
.
AddTransient
(
typeof
(
UnitOfWork
));
//
注入工作单元
//
配置跨域处理,允许所有来源
//
配置跨域处理,允许所有来源
services
.
AddCors
(
options
=>
services
.
AddCors
(
options
=>
{
{
options
.
AddPolicy
(
"cors"
,
options
.
AddPolicy
(
"cors"
,
...
@@ -69,7 +69,7 @@ namespace ApiSys
...
@@ -69,7 +69,7 @@ namespace ApiSys
x
.
MultipartBodyLengthLimit
=
int
.
MaxValue
;
x
.
MultipartBodyLengthLimit
=
int
.
MaxValue
;
x
.
MultipartHeadersLengthLimit
=
int
.
MaxValue
;
x
.
MultipartHeadersLengthLimit
=
int
.
MaxValue
;
});
});
//
添加NACOS配置
//
添加NACOS配置
services
.
AddNacosNaming
(
Configuration
)
services
.
AddNacosNaming
(
Configuration
)
.
AddNacosConfig
(
Configuration
)
.
AddNacosConfig
(
Configuration
)
.
AddNacosAspNetCore
(
Configuration
);
.
AddNacosAspNetCore
(
Configuration
);
...
@@ -87,7 +87,7 @@ namespace ApiSys
...
@@ -87,7 +87,7 @@ namespace ApiSys
options
.
UseSqlServer
(
connection
);
options
.
UseSqlServer
(
connection
);
});
});
#
region
身份认证
#
region
身份认证
services
.
AddSession
(
options
=>
services
.
AddSession
(
options
=>
{
{
options
.
Cookie
.
HttpOnly
=
true
;
options
.
Cookie
.
HttpOnly
=
true
;
...
@@ -101,14 +101,14 @@ namespace ApiSys
...
@@ -101,14 +101,14 @@ namespace ApiSys
options
.
DataProtectionProvider
=
DataProtectionProvider
.
Create
(
new
DirectoryInfo
(
AppDomain
.
CurrentDomain
.
BaseDirectory
+
"/shared-auth-ticket-keys/"
));
options
.
DataProtectionProvider
=
DataProtectionProvider
.
Create
(
new
DirectoryInfo
(
AppDomain
.
CurrentDomain
.
BaseDirectory
+
"/shared-auth-ticket-keys/"
));
options
.
Cookie
.
Path
=
"/"
;
options
.
Cookie
.
Path
=
"/"
;
options
.
LoginPath
=
new
PathString
(
"/Login/Index"
);
options
.
LoginPath
=
new
PathString
(
"/Login/Index"
);
options
.
AccessDeniedPath
=
new
PathString
(
"/Forbidden"
);
//
禁止访问路径:当用户试图访问资源时,但未通过该资源的任何授权策略,请求将被重定向到这个相对路径。
options
.
AccessDeniedPath
=
new
PathString
(
"/Forbidden"
);
//
禁止访问路径:当用户试图访问资源时,但未通过该资源的任何授权策略,请求将被重定向到这个相对路径。
// options.SlidingExpiration = false; //Cookie
可以分为永久性的和临时性的。 临时性的是指只在当前浏览器进程里有效,浏览器一旦关闭就失效(被浏览器删除)。 永久性的是指Cookie指定了一个过期时间,在这个时间到达之前,此cookie一直有效(浏览器一直记录着此cookie的存在)。 slidingExpriation的作用是,指示浏览器把cookie作为永久性cookie存储,但是会自动更改过期时间,以使用户不会在登录后并一直活动,但是一段时间后却自动注销。也就是说,你10点登录了,服务器端设置的TimeOut为30分钟,如果slidingExpriation为false,那么10:30以后,你就必须重新登录。如果为true的话,你10:16分时打开了一个新页面,服务器就会通知浏览器,把过期时间修改为10:46。 更详细的说明还是参考MSDN的文档。
// options.SlidingExpiration = false; //Cookie
可以分为永久性的和临时性的。 临时性的是指只在当前浏览器进程里有效,浏览器一旦关闭就失效(被浏览器删除)。 永久性的是指Cookie指定了一个过期时间,在这个时间到达之前,此cookie一直有效(浏览器一直记录着此cookie的存在)。 slidingExpriation的作用是,指示浏览器把cookie作为永久性cookie存储,但是会自动更改过期时间,以使用户不会在登录后并一直活动,但是一段时间后却自动注销。也就是说,你10点登录了,服务器端设置的TimeOut为30分钟,如果slidingExpriation为false,那么10:30以后,你就必须重新登录。如果为true的话,你10:16分时打开了一个新页面,服务器就会通知浏览器,把过期时间修改为10:46。 更详细的说明还是参考MSDN的文档。
});
});
#
endregion
#
endregion
services
.
AddSession
();
services
.
AddSession
();
////
启动
MQTT
////
启动M
QTT
//var mqtt = new MQTTServer(connection);
//var mqtt = new MQTTServer(connection);
//mqtt.StartMqttServer(Configuration);
//mqtt.StartMqttServer(Configuration);
//services.AddSingleton(mqtt);
//services.AddSingleton(mqtt);
...
@@ -132,8 +132,8 @@ namespace ApiSys
...
@@ -132,8 +132,8 @@ namespace ApiSys
app
.
UseHttpsRedirection
();
app
.
UseHttpsRedirection
();
app
.
UseRouting
();
app
.
UseRouting
();
app
.
UseAuthorization
();
app
.
UseAuthorization
();
//
允许所有跨域,cors是在ConfigureServices方法中配置的跨域策略名称
//
允许所有跨域,cors是在ConfigureServices方法中配置的跨域策略名称
//
注意:UseCors必须放在UseRouting和UseEndpoints之间
//
注意:UseCors必须放在UseRouting和UseEndpoints之间
app
.
UseCors
(
"cors"
);
app
.
UseCors
(
"cors"
);
app
.
UseAuthentication
();
app
.
UseAuthentication
();
app
.
UseEndpoints
(
endpoints
=>
app
.
UseEndpoints
(
endpoints
=>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论