转换文件编码

This commit is contained in:
不做码农
2022-06-01 17:25:41 +08:00
parent 3b8ec3cc95
commit b4dceca92f
3 changed files with 70 additions and 70 deletions
+6 -6
View File
@@ -1,21 +1,21 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
#创建 /app文件夹
#创建 /app文件夹
WORKDIR /app
#创建挂载目录,用于将程序部署在服务器本地
#创建挂载目录,用于将程序部署在服务器本地
#VOLUME /app
#设置docker容器对外暴露端口
#设置docker容器对外暴露端口
EXPOSE 8888
VOLUME /app/logs
#COPY bin/Release/net5.0/publish/ app/
COPY . app/
#设置容器内的时区,如果不设置,默认时区是标准时间比北京时间晚8个小时
#设置容器内的时区,如果不设置,默认时区是标准时间比北京时间晚8个小时
RUN echo "Asia/shanghai" > /etc/timezone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 复制发布文件到工作目录
# 复制发布文件到工作目录
#COPY . app/
WORKDIR /app
#等价于 dotnet ZR.Admin.WebApi.dll,如果不指定启动端口默认在docker里面启动端口是80端口
#等价于 dotnet ZR.Admin.WebApi.dll,如果不指定启动端口默认在docker里面启动端口是80端口
ENTRYPOINT ["dotnet", "ZR.Admin.WebApi.dll", "--server.urls","http://*:8888"]
+31 -31
View File
@@ -33,39 +33,39 @@ namespace ZR.Admin.WebApi
{
string corsUrls = Configuration["corsUrls"];
//配置跨域
//配置跨域
services.AddCors(c =>
{
c.AddPolicy("Policy", policy =>
{
policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries))
.AllowAnyHeader()//允许任意头
.AllowCredentials()//允许cookie
.AllowAnyMethod();//允许任意方法
.AllowAnyHeader()//允许任意头
.AllowCredentials()//允许cookie
.AllowAnyMethod();//允许任意方法
});
});
//注入SignalR实时通讯,默认用json传输
//注入SignalR实时通讯,默认用json传输
services.AddSignalR(options =>
{
//客户端发保持连接请求到服务端最长间隔,默认30秒,改成4分钟,网页需跟着设置connection.keepAliveIntervalInMilliseconds = 12e4;即2分钟
//客户端发保持连接请求到服务端最长间隔,默认30秒,改成4分钟,网页需跟着设置connection.keepAliveIntervalInMilliseconds = 12e4;即2分钟
//options.ClientTimeoutInterval = TimeSpan.FromMinutes(4);
//服务端发保持连接请求到客户端间隔,默认15秒,改成2分钟,网页需跟着设置connection.serverTimeoutInMilliseconds = 24e4;即4分钟
//服务端发保持连接请求到客户端间隔,默认15秒,改成2分钟,网页需跟着设置connection.serverTimeoutInMilliseconds = 24e4;即4分钟
//options.KeepAliveInterval = TimeSpan.FromMinutes(2);
});
//消除Error unprotecting the session cookie警告
//消除Error unprotecting the session cookie警告
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
//普通验证码
//普通验证码
services.AddHeiCaptcha();
services.AddIPRate(Configuration);
services.AddSession();
services.AddMemoryCache();
services.AddHttpContextAccessor();
//绑定整个对象到Model上
//绑定整个对象到Model上
services.Configure<OptionsSetting>(Configuration);
//jwt 认证
//jwt 认证
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@@ -80,7 +80,7 @@ namespace ZR.Admin.WebApi
services.AddMvc(options =>
{
options.Filters.Add(typeof(GlobalActionMonitor));//全局注册
options.Filters.Add(typeof(GlobalActionMonitor));//全局注册
})
.AddJsonOptions(options =>
{
@@ -99,7 +99,7 @@ namespace ZR.Admin.WebApi
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
//使可以多次多去body内容
//使可以多次多去body内容
app.Use((context, next) =>
{
context.Request.EnableBuffering();
@@ -109,33 +109,33 @@ namespace ZR.Admin.WebApi
}
return next();
});
//开启访问静态文件/wwwroot目录文件,要放在UseRouting前面
//开启访问静态文件/wwwroot目录文件,要放在UseRouting前面
app.UseStaticFiles();
//开启路由访问
//开启路由访问
app.UseRouting();
app.UseCors("Policy");//要放在app.UseEndpoints前。
app.UseCors("Policy");//要放在app.UseEndpoints前。
//app.UseAuthentication会启用Authentication中间件,该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性(后面会用到),
//所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值,
//这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面,因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。
//1.先开启认证
//app.UseAuthentication会启用Authentication中间件,该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性(后面会用到),
//所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值,
//这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面,因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。
//1.先开启认证
app.UseAuthentication();
//2.再开启授权
//2.再开启授权
app.UseAuthorization();
//开启session
//开启session
//app.UseSession();
//开启缓存
//开启缓存
app.UseResponseCaching();
//恢复/启动任务
//恢复/启动任务
app.UseAddTaskSchedulers();
//使用全局异常中间件
//使用全局异常中间件
app.UseMiddleware<GlobalExceptionMiddleware>();
//启用客户端IP限制速率
//启用客户端IP限制速率
app.UseIpRateLimiting();
app.UseEndpoints(endpoints =>
{
//设置socket连接
//设置socket连接
endpoints.MapHub<MessageHub>("/msgHub");
endpoints.MapControllerRoute(
@@ -145,7 +145,7 @@ namespace ZR.Admin.WebApi
}
/// <summary>
/// 注册Services服务
/// 注册Services服务
/// </summary>
/// <param name="services"></param>
/// <param name="configuration"></param>
@@ -153,12 +153,12 @@ namespace ZR.Admin.WebApi
{
services.AddAppService();
services.AddSingleton(new AppSettings(configuration));
//开启计划任务
//开启计划任务
services.AddTaskSchedulers();
//初始化db
//初始化db
DbExtension.AddDb(configuration);
//注册REDIS 服务
//注册REDIS 服务
Task.Run(() =>
{
//RedisServer.Initalize();
+33 -33
View File
@@ -7,97 +7,97 @@
}
},
"ConnectionStrings": {
"conn_db": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", //其他连接字符串请看官方文档
"conn_db_type": "1" //数据库类型 MySql = 0, SqlServer = 1
"conn_db": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", //其他连接字符串请看官方文档
"conn_db_type": "1" //数据库类型 MySql = 0, SqlServer = 1
},
"urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
"corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
"urls": "http://localhost:8888", //项目启动url,如果改动端口前端对应devServer也需要进行修改
"corsUrls": "http://localhost:8887", //跨域地址(前端启动项目,前后端分离单独部署需要设置),多个用","隔开
"JwtSettings": {
"Issuer": "ZRAdmin.NET",
"Audience": "ZRAdmin.NET",
"SecretKey": "SecretKey-ZRADMIN.NET-20210101",
"Expire": 1440 //jwt登录过期时间(分)
"Expire": 1440 //jwt登录过期时间(分)
},
"DemoMode": false, //是否演示模式
"DemoMode": false, //是否演示模式
"Upload": {
"UploadUrl": "http://localhost:8888",
"localSavePath": "" //本地上传文件存储目录/home/website/uploads
"localSavePath": "" //本地上传文件存储目录/home/website/uploads
},
//阿里云存储配置
//阿里云存储配置
"ALIYUN_OSS": {
"REGIONID": "cn-hangzhou",
"KEY": "XX",
"SECRET": "XX",
"bucketName": "bucketName",
"domainUrl": "http://xxx.xxx.com" //访问资源域名
"domainUrl": "http://xxx.xxx.com" //访问资源域名
},
"gen": {
"conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI",
"dbType": 1, //MySql = 0, SqlServer = 1
"autoPre": true, //自动去除表前缀
"autoPre": true, //自动去除表前缀
"author": "admin",
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "" //前端代码存储路径eg:D:\Work\ZRAdmin-Vue3
},
//邮箱配置信息
//邮箱配置信息
"MailOptions": {
//发送人邮箱
"From": "", //eg:xxxx@qq.com
//发送人邮箱密码
//发送人邮箱
"From": "", //eg:xxxx@qq.com
//发送人邮箱密码
"Password": "123456",
//协议
//协议
"Smtp": "smtp.qq.com",
"Port": 587
},
//redis服务配置
//redis服务配置
"RedisServer": {
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
},
//接口请求限制
//接口请求限制
"IpRateLimiting": {
//例如设置了5次每分钟访问限流。当False时:项目中每个接口都加入计数,不管你访问哪个接口,只要在一分钟内累计够5次,将禁止访问。
//True:当一分钟请求了5次GetData接口,则该接口将在时间段内禁止访问,但是还可以访问PostData()5次,总得来说是每个接口都有5次在这一分钟,互不干扰。
//例如设置了5次每分钟访问限流。当False时:项目中每个接口都加入计数,不管你访问哪个接口,只要在一分钟内累计够5次,将禁止访问。
//True:当一分钟请求了5次GetData接口,则该接口将在时间段内禁止访问,但是还可以访问PostData()5次,总得来说是每个接口都有5次在这一分钟,互不干扰。
"EnableEndpointRateLimiting": true,
//false,拒绝的API调用不会添加到调用次数计数器上;如 客户端每秒发出3个请求并且您设置了每秒一个调用的限制,则每分钟或每天计数器等其他限制将仅记录第一个调用,即成功的API调用。如果您希望被拒绝的API调用计入其他时间的显示(分钟,小时等)
//,则必须设置StackBlockedRequests为true。
//false,拒绝的API调用不会添加到调用次数计数器上;如 客户端每秒发出3个请求并且您设置了每秒一个调用的限制,则每分钟或每天计数器等其他限制将仅记录第一个调用,即成功的API调用。如果您希望被拒绝的API调用计入其他时间的显示(分钟,小时等)
//,则必须设置StackBlockedRequests为true。
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
//取白名单的客户端ID。如果此标头中存在客户端ID并且与ClientWhitelist中指定的值匹配,则不应用速率限制。
//取白名单的客户端ID。如果此标头中存在客户端ID并且与ClientWhitelist中指定的值匹配,则不应用速率限制。
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
//端点白名单
//端点白名单
"EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ],
//客户端白名单
//客户端白名单
//"ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
"QuotaExceededResponse": {
"Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}",
"Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}",
"ContentType": "application/json",
"StatusCode": 429
},
//通用规则,api规则,结尾一定要带*
//通用规则,api规则,结尾一定要带*
"GeneralRules": [
{
"Endpoint": "*:/captchaImage",
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d
"Period": "3s",
"Limit": 5
},
{
"Endpoint": "post:*",
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d
"Period": "3s",
"Limit": 1
},
{
"Endpoint": "put:*",
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d
//时间段,格式:{数字}{单位};可使用单位:s, m, h, d
"Period": "3s",
"Limit": 1
}
//{
// "Endpoint": "*",
// //时间段,格式:{数字}{单位};可使用单位:s, m, h, d
// //时间段,格式:{数字}{单位};可使用单位:s, m, h, d
// "Period": "1s",
// "Limit": 2
//}
@@ -118,7 +118,7 @@
//}
],
"IpRateLimitPolicies": {
//ip规则
//ip规则
"IpRules": [
]
}