转换文件编码

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

View File

@ -1,21 +1,21 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
#创建 /app文件夹 #创建 /app文件夹
WORKDIR /app WORKDIR /app
#创建挂载目录,用于将程序部署在服务器本地 #创建挂载目录,用于将程序部署在服务器本地
#VOLUME /app #VOLUME /app
#设置docker容器对外暴露端口 #设置docker容器对外暴露端口
EXPOSE 8888 EXPOSE 8888
VOLUME /app/logs VOLUME /app/logs
#COPY bin/Release/net5.0/publish/ app/ #COPY bin/Release/net5.0/publish/ app/
COPY . app/ COPY . app/
#设置容器内的时区如果不设置默认时区是标准时间比北京时间晚8个小时 #设置容器内的时区如果不设置默认时区是标准时间比北京时间晚8个小时
RUN echo "Asia/shanghai" > /etc/timezone RUN echo "Asia/shanghai" > /etc/timezone
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 复制发布文件到工作目录 # 复制发布文件到工作目录
#COPY . app/ #COPY . app/
WORKDIR /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"] ENTRYPOINT ["dotnet", "ZR.Admin.WebApi.dll", "--server.urls","http://*:8888"]

View File

@ -33,39 +33,39 @@ namespace ZR.Admin.WebApi
{ {
string corsUrls = Configuration["corsUrls"]; string corsUrls = Configuration["corsUrls"];
//配置跨域 //配置跨域
services.AddCors(c => services.AddCors(c =>
{ {
c.AddPolicy("Policy", policy => c.AddPolicy("Policy", policy =>
{ {
policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries)) policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries))
.AllowAnyHeader()//允许任意头 .AllowAnyHeader()//允许任意头
.AllowCredentials()//允许cookie .AllowCredentials()//允许cookie
.AllowAnyMethod();//允许任意方法 .AllowAnyMethod();//允许任意方法
}); });
}); });
//注入SignalR实时通讯默认用json传输 //注入SignalR实时通讯默认用json传输
services.AddSignalR(options => services.AddSignalR(options =>
{ {
//客户端发保持连接请求到服务端最长间隔默认30秒改成4分钟网页需跟着设置connection.keepAliveIntervalInMilliseconds = 12e4;即2分钟 //客户端发保持连接请求到服务端最长间隔默认30秒改成4分钟网页需跟着设置connection.keepAliveIntervalInMilliseconds = 12e4;即2分钟
//options.ClientTimeoutInterval = TimeSpan.FromMinutes(4); //options.ClientTimeoutInterval = TimeSpan.FromMinutes(4);
//服务端发保持连接请求到客户端间隔默认15秒改成2分钟网页需跟着设置connection.serverTimeoutInMilliseconds = 24e4;即4分钟 //服务端发保持连接请求到客户端间隔默认15秒改成2分钟网页需跟着设置connection.serverTimeoutInMilliseconds = 24e4;即4分钟
//options.KeepAliveInterval = TimeSpan.FromMinutes(2); //options.KeepAliveInterval = TimeSpan.FromMinutes(2);
}); });
//消除Error unprotecting the session cookie警告 //消除Error unprotecting the session cookie警告
services.AddDataProtection() services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection")); .PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
//普通验证码 //普通验证码
services.AddHeiCaptcha(); services.AddHeiCaptcha();
services.AddIPRate(Configuration); services.AddIPRate(Configuration);
services.AddSession(); services.AddSession();
services.AddMemoryCache(); services.AddMemoryCache();
services.AddHttpContextAccessor(); services.AddHttpContextAccessor();
//绑定整个对象到Model上 //绑定整个对象到Model上
services.Configure<OptionsSetting>(Configuration); services.Configure<OptionsSetting>(Configuration);
//jwt 认证 //jwt 认证
services.AddAuthentication(options => services.AddAuthentication(options =>
{ {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
@ -80,7 +80,7 @@ namespace ZR.Admin.WebApi
services.AddMvc(options => services.AddMvc(options =>
{ {
options.Filters.Add(typeof(GlobalActionMonitor));//全局注册 options.Filters.Add(typeof(GlobalActionMonitor));//全局注册
}) })
.AddJsonOptions(options => .AddJsonOptions(options =>
{ {
@ -99,7 +99,7 @@ namespace ZR.Admin.WebApi
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
app.UseSwagger(); app.UseSwagger();
//使可以多次多去body内容 //使可以多次多去body内容
app.Use((context, next) => app.Use((context, next) =>
{ {
context.Request.EnableBuffering(); context.Request.EnableBuffering();
@ -109,33 +109,33 @@ namespace ZR.Admin.WebApi
} }
return next(); return next();
}); });
//开启访问静态文件/wwwroot目录文件要放在UseRouting前面 //开启访问静态文件/wwwroot目录文件要放在UseRouting前面
app.UseStaticFiles(); app.UseStaticFiles();
//开启路由访问 //开启路由访问
app.UseRouting(); app.UseRouting();
app.UseCors("Policy");//要放在app.UseEndpoints前。 app.UseCors("Policy");//要放在app.UseEndpoints前。
//app.UseAuthentication会启用Authentication中间件该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性后面会用到 //app.UseAuthentication会启用Authentication中间件该中间件会根据当前Http请求中的Cookie信息来设置HttpContext.User属性后面会用到
//所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值 //所以只有在app.UseAuthentication方法之后注册的中间件才能够从HttpContext.User中读取到值
//这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。 //这也是为什么上面强调app.UseAuthentication方法一定要放在下面的app.UseMvc方法前面因为只有这样ASP.NET Core的MVC中间件中才能读取到HttpContext.User的值。
//1.先开启认证 //1.先开启认证
app.UseAuthentication(); app.UseAuthentication();
//2.再开启授权 //2.再开启授权
app.UseAuthorization(); app.UseAuthorization();
//开启session //开启session
//app.UseSession(); //app.UseSession();
//开启缓存 //开启缓存
app.UseResponseCaching(); app.UseResponseCaching();
//恢复/启动任务 //恢复/启动任务
app.UseAddTaskSchedulers(); app.UseAddTaskSchedulers();
//使用全局异常中间件 //使用全局异常中间件
app.UseMiddleware<GlobalExceptionMiddleware>(); app.UseMiddleware<GlobalExceptionMiddleware>();
//启用客户端IP限制速率 //启用客户端IP限制速率
app.UseIpRateLimiting(); app.UseIpRateLimiting();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
//设置socket连接 //设置socket连接
endpoints.MapHub<MessageHub>("/msgHub"); endpoints.MapHub<MessageHub>("/msgHub");
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
@ -145,7 +145,7 @@ namespace ZR.Admin.WebApi
} }
/// <summary> /// <summary>
/// 注册Services服务 /// 注册Services服务
/// </summary> /// </summary>
/// <param name="services"></param> /// <param name="services"></param>
/// <param name="configuration"></param> /// <param name="configuration"></param>
@ -153,12 +153,12 @@ namespace ZR.Admin.WebApi
{ {
services.AddAppService(); services.AddAppService();
services.AddSingleton(new AppSettings(configuration)); services.AddSingleton(new AppSettings(configuration));
//开启计划任务 //开启计划任务
services.AddTaskSchedulers(); services.AddTaskSchedulers();
//初始化db //初始化db
DbExtension.AddDb(configuration); DbExtension.AddDb(configuration);
//注册REDIS 服务 //注册REDIS 服务
Task.Run(() => Task.Run(() =>
{ {
//RedisServer.Initalize(); //RedisServer.Initalize();

View File

@ -7,97 +7,97 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"conn_db": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", // "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_type": "1" // MySql = 0, SqlServer = 1
}, },
"urls": "http://localhost:8888", //urldevServer "urls": "http://localhost:8888", //urldevServer
"corsUrls": "http://localhost:8887", //"," "corsUrls": "http://localhost:8887", //","
"JwtSettings": { "JwtSettings": {
"Issuer": "ZRAdmin.NET", "Issuer": "ZRAdmin.NET",
"Audience": "ZRAdmin.NET", "Audience": "ZRAdmin.NET",
"SecretKey": "SecretKey-ZRADMIN.NET-20210101", "SecretKey": "SecretKey-ZRADMIN.NET-20210101",
"Expire": 1440 //jwt "Expire": 1440 //jwt
}, },
"DemoMode": false, // "DemoMode": false, //
"Upload": { "Upload": {
"UploadUrl": "http://localhost:8888", "UploadUrl": "http://localhost:8888",
"localSavePath": "" ///home/website/uploads "localSavePath": "" ///home/website/uploads
}, },
// //
"ALIYUN_OSS": { "ALIYUN_OSS": {
"REGIONID": "cn-hangzhou", "REGIONID": "cn-hangzhou",
"KEY": "XX", "KEY": "XX",
"SECRET": "XX", "SECRET": "XX",
"bucketName": "bucketName", "bucketName": "bucketName",
"domainUrl": "http://xxx.xxx.com" //访 "domainUrl": "http://xxx.xxx.com" //访
}, },
"gen": { "gen": {
"conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI", "conn": "Data Source=LAPTOP-STKF2M8H\\SQLEXPRESS;User ID=sa;Password=zradmin123;Initial Catalog=ZrAdmin;Integrated Security=SSPI",
"dbType": 1, //MySql = 0, SqlServer = 1 "dbType": 1, //MySql = 0, SqlServer = 1
"autoPre": true, // "autoPre": true, //
"author": "admin", "author": "admin",
"tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)", "tablePrefix": "sys_", //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
"vuePath": "" //egD:\Work\ZRAdmin-Vue3 "vuePath": "" //egD:\Work\ZRAdmin-Vue3
}, },
// //
"MailOptions": { "MailOptions": {
// //
"From": "", //egxxxx@qq.com "From": "", //egxxxx@qq.com
// //
"Password": "123456", "Password": "123456",
// //
"Smtp": "smtp.qq.com", "Smtp": "smtp.qq.com",
"Port": 587 "Port": 587
}, },
//redis //redis
"RedisServer": { "RedisServer": {
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:", "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:" "Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
}, },
// //
"IpRateLimiting": { "IpRateLimiting": {
//5访False访5访 //5访False访5访
//True5GetData访访PostData()5,5 //True5GetData访访PostData()5,5
"EnableEndpointRateLimiting": true, "EnableEndpointRateLimiting": true,
//falseAPI; 3APIAPI //falseAPI; 3APIAPI
//StackBlockedRequeststrue //StackBlockedRequeststrue
"StackBlockedRequests": false, "StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP", "RealIpHeader": "X-Real-IP",
//IDIDClientWhitelist //IDIDClientWhitelist
"ClientIdHeader": "X-ClientId", "ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429, "HttpStatusCode": 429,
// //
"EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ], "EndpointWhitelist": [ "post:/system/dict/data/types", "*:/msghub/negotiate", "*:/LogOut" ],
// //
//"ClientWhitelist": [ "dev-id-1", "dev-id-2" ], //"ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
"QuotaExceededResponse": { "QuotaExceededResponse": {
"Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}", "Content": "{{\"code\":429,\"msg\":\"访问过于频繁,请稍后重试\"}}",
"ContentType": "application/json", "ContentType": "application/json",
"StatusCode": 429 "StatusCode": 429
}, },
//api,* //api,*
"GeneralRules": [ "GeneralRules": [
{ {
"Endpoint": "*:/captchaImage", "Endpoint": "*:/captchaImage",
//{}{}使s, m, h, d //{}{}使s, m, h, d
"Period": "3s", "Period": "3s",
"Limit": 5 "Limit": 5
}, },
{ {
"Endpoint": "post:*", "Endpoint": "post:*",
//{}{}使s, m, h, d //{}{}使s, m, h, d
"Period": "3s", "Period": "3s",
"Limit": 1 "Limit": 1
}, },
{ {
"Endpoint": "put:*", "Endpoint": "put:*",
//{}{}使s, m, h, d //{}{}使s, m, h, d
"Period": "3s", "Period": "3s",
"Limit": 1 "Limit": 1
} }
//{ //{
// "Endpoint": "*", // "Endpoint": "*",
// //{}{}使s, m, h, d // //{}{}使s, m, h, d
// "Period": "1s", // "Period": "1s",
// "Limit": 2 // "Limit": 2
//} //}
@ -118,7 +118,7 @@
//} //}
], ],
"IpRateLimitPolicies": { "IpRateLimitPolicies": {
//ip //ip
"IpRules": [ "IpRules": [
] ]
} }