
配置项说明
命名空间:
ZhonTai.Admin.Core.Configs
中台 Admin 的核心配置文件为 appconfig.json,对应 AppConfig 类。此外还有数据库、JWT、邮件、OSS、缓存、限流等独立配置。
AppConfig 主配置
配置文件:
Configs/appconfig.json
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
AppType | string | 应用程序类型:Controllers / ControllersWithViews / MVC |
Urls | string[] | 监听地址列表,如 [ "http://*:18010" ] |
CorUrls | string[] | 跨域地址列表 |
AssemblyNames | string[] | 要扫描的程序集名称列表 |
EnumListAssemblyNames | string[] | 枚举列表程序集名称 |
Tenant | bool | 是否启用多租户 |
DistributeKey | string | 分布式事务唯一标识,为空则不生成分布式事务表 |
DefaultPassword | string | 默认密码 |
Lang | object | 语言配置 |
Lang.EnableJson | bool | 启用语言配置 |
Lang.DefaultLang | string | 默认语言,如 zh-CN |
Lang.Langs | string[] | 支持的语言列表 |
Lang.RequestCultureProviders | string[] | 语言请求解析列表:QueryString、Cookie、AcceptLanguageHeader |
Validate | object | 验证配置 |
Validate.Login | bool | 启用登录验证 |
Validate.Permission | bool | 启用权限验证 |
Validate.DataPermission | bool | 启用数据权限 |
Validate.ApiDataPermission | bool | 启用接口级数据权限 |
Aop | object | AOP 配置 |
Aop.Transaction | bool | 启用声明式事务 |
Swagger | object | Swagger 配置 |
Swagger.Enable | bool | 启用 Swagger |
Swagger.EnableEnumSchemaFilter | bool | 启用枚举架构过滤器 |
Swagger.EnableOrderTagsDocumentFilter | bool | 启用接口排序文档过滤器 |
Swagger.EnableJsonStringEnumConverter | bool | 启用枚举属性名 |
Swagger.EnableSchemaIdNamespace | bool | 启用 SchemaId 命名空间 |
Swagger.AssemblyNameList | string[] | 用于启用 SchemaId 命名空间的程序集列表 |
Swagger.RoutePrefix | string | 路由前缀,如配置微服务文档地址:doc/module/swagger |
Swagger.Url | string | Swagger 地址 |
Swagger.Projects | object[] | Swagger 项目分组列表 |
ApiUI | object | 新版接口文档展示配置 |
ApiUI.Enable | bool | 启用 |
ApiUI.RoutePrefix | string | 路由前缀 |
ApiUI.Footer | object | 页脚配置 |
MiniProfiler | bool | 启用 MiniProfiler 性能分析器 |
Log | object | 日志配置 |
Log.Operation | bool | 启用操作日志 |
Log.Method | string | 记录日志方式:Grpc / Cap |
RateLimit | bool | 启用限流 |
VarifyCode | object | 验证码配置 |
VarifyCode.Enable | bool | 启用验证码 |
VarifyCode.Fonts | string[] | 字体列表 |
DynamicApi | object | 动态 API 配置 |
DynamicApi.FormatResult | bool | 启用结果格式化 |
PasswordHasher | bool | 实现标准标识密码哈希 |
Kestrel | object | Kestrel 服务器配置 |
Kestrel.KeepAliveTimeout | int | HTTP 连接保活最长时间(秒) |
Kestrel.RequestHeadersTimeout | int | 发送请求头最长时间(秒) |
Kestrel.MaxRequestBodySize | long | 最大请求大小(bytes),null 不限制 |
HealthChecks | object | 健康检查配置 |
HealthChecks.Enable | bool | 启用健康检查 |
HealthChecks.Path | string | 健康检查访问路径 |
PreflightMaxAge | int | 跨域预检等待时间(秒),默认 1800 |
TaskSchedulerUI | object | 任务调度管理界面 |
TaskSchedulerUI.Enable | bool | 启用任务调度管理界面 |
TaskSchedulerUI.Path | string | 访问路径 |
IdGenerator | object | ID 生成器配置 |
IdGenerator.DataCenterId | int | 数据中心 ID |
IdGenerator.WorkerId | int | 机器码,必须全局唯一 |
IdGenerator.WorkerIdBitLength | int | 机器码位长,默认 6 |
IdGenerator.SeqBitLength | int | 序列数位长,默认 6 |
IdGenerator.CachePrefix | string | 缓存前缀 |
IP2Region | object | IP 地址定位配置 |
IP2Region.Enable | bool | 启用 IP 地址定位 |
IP2Region.DbPath | string | 绝对数据库路径,为空则默认使用网站根目录 ip2region.xdb |
配置示例
json
{
"AppConfig": {
"appType": "Controllers",
"urls": [ "http://*:18010" ],
"corUrls": [],
"assemblyNames": [ "ZhonTai.Admin.Core", "ZhonTai.Module.Admin" ],
"EnumListAssemblyNames": [],
"tenant": true,
"distributeKey": "",
"validate": {
"login": true,
"permission": true,
"dataPermission": true,
"apiDataPermission": true
},
"swagger": {
"enable": true,
"enableEnumSchemaFilter": true,
"enableOrderTagsDocumentFilter": true,
"enableJsonStringEnumConverter": false,
"enableSchemaIdNamespace": false,
"assemblyNameList": [],
"routePrefix": "doc/sys/swagger",
"url": "http://localhost:18010",
"projects": [
{
"name": "中台Admin",
"code": "admin",
"version": "v10.0.1",
"description": "权限管理"
}
]
},
"apiUI": {
"enable": true,
"routePrefix": "doc/sys",
"footer": {
"enable": false,
"content": ""
}
},
"miniProfiler": false,
"aop": {
"transaction": true
},
"log": {
"operation": true,
"method": "Grpc"
},
"rateLimit": false,
"varifyCode": {
"enable": true,
"fonts": [ "Times New Roman", "Verdana", "Arial", "Gungsuh", "Impact" ]
},
"defaultPassword": "123asd",
"dynamicApi": {
"formatResult": true
},
"passwordHasher": false,
"Kestrel": {
"KeepAliveTimeout": 600,
"RequestHeadersTimeout": 600,
"maxRequestBodySize": 104857600
},
"healthChecks": {
"enable": true,
"path": "/health"
},
"PreflightMaxAge": 1800,
"TaskSchedulerUI": {
"enable": true,
"path": "/task"
},
"IdGenerator": {
"DataCenterId": 0,
"WorkerId": 1,
"WorkerIdBitLength": 6,
"SeqBitLength": 6,
"CachePrefix": "zhontai:workerid"
},
"IP2Region": {
"Enable": true,
"DbPath": ""
},
"Lang": {
"EnableJson": true,
"DefaultLang": "zh-CN",
"Langs": [ "zh-CN", "en" ],
"RequestCultureProviders": []
}
}
}DbConfig 数据库配置
配置文件:
Configs/dbconfig.json
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
Key | string | 数据库注册键(如 AdminDb、LogDb) |
Type | string | 数据库类型:MySql / SqlServer / PostgreSQL / Sqlite / Oracle / TiDB 等 |
ConnectionString | string | 连接字符串 |
AssemblyNames | string[] | 程序集名称,自动获取实体表,为空则通过 ConfigureFreeSql 自定义配置 |
IncludeEntityDbs | string[] | 指定实体数据库列表,不填同步所有数据库表实体 |
ExcludeEntityDbs | string[] | 排除实体数据库列表,指定不同步数据库表实体 |
MonitorCommand | bool | 监听所有操作 |
Curd | bool | 监听 Curd 操作 |
SyncStructureSql | bool | 监听同步结构脚本 |
SyncDataCurd | bool | 监听同步数据 Curd 操作 |
CreateDb | bool | 建库 |
CreateDbConnectionString | string | 建库连接字符串 |
CreateDbSql | string | 建库脚本 |
SyncStructure | bool | 自动同步表结构 |
SyncStructureEntityBatchSize | int | 同步结构批次实体数 |
SyncDataBatchSize | int | 同步数据分批处理大小,默认 500,过大可能会导致内存溢出 |
SyncData | bool | 自动同步种子数据 |
SyncUpdateData | bool | 同步更新数据,生产环境谨慎开启 |
SyncDataPath | string | 同步数据地址 |
SyncDataIncludeTables | string[] | 同步数据包含表,指定表同步,不填同步所有表 |
SyncDataExcludeTables | string[] | 同步数据排除表,指定表不同步 |
SyncDataUser | object | 同步数据操作用户 |
GenerateData | bool | 生成种子数据包,发布生产环境前使用完记得关闭 |
ProviderType | string | 指定程序集 |
SlaveList | object[] | 读写分离从库列表 |
IdleTime | int | 空闲时间(分),0 不自动回收 |
ForceUpdate | bool | 新增时强制更新 EntityUpdate 数据 |
Dbs | object[] | 多库配置(子库列表) |
配置示例
json
{
"DbConfig": {
"key": "sysdb",
"assemblyNames": [ "ZhonTai.Admin" ],
"type": "MySql",
"connectionString": "Server=localhost;Port=3306;Database=sysdb;Uid=root;Pwd=pwd;Charset=utf8mb4;Min pool size=1;Allow User Variables=True",
"createDb": true,
"createDbConnectionString": "Server=localhost;Port=3306;Database=mysql;Uid=root;Pwd=pwd;Charset=utf8mb4;Min pool size=1;Allow User Variables=True",
"createDbSql": "CREATE DATABASE `sysdb` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci'",
"syncStructure": true,
"syncStructureEntityBatchSize": 1,
"syncDataBatchSize": 500,
"syncData": true,
"syncUpdateData": false,
"SyncDataPath": "InitData/App",
"syncDataIncludeTables": [],
"syncDataExcludeTables": [],
"syncDataUser": {
"id": 161223411986501,
"userName": "admin",
"name": "管理员",
"tenantId": 161223412138053
},
"generateData": false,
"idleTime": 1440,
"forceUpdate": false,
"dbs": [
{
"key": "admindb",
"assemblyNames": [ "ZhonTai.Admin" ],
"type": "MySql",
"connectionString": "Server=localhost;Port=3306;Database=admindb;Uid=root;Pwd=pwd;Charset=utf8mb4;Min pool size=1;Allow User Variables=True"
},
{
"key": "logdb",
"assemblyNames": [ "ZhonTai.Admin" ],
"includeEntityDbs": [ "Log" ],
"type": "MySql",
"connectionString": "Server=localhost;Port=3306;Database=logdb;Uid=root;Pwd=pwd;Charset=utf8mb4;Min pool size=1;Allow User Variables=True"
}
]
}
}JwtConfig JWT 配置
配置文件:
Configs/jwtconfig.json
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
Issuer | string | 发行者 |
Audience | string | 订阅者 |
SecurityKey | string | 密钥,自定义 |
Expires | int | Access Token 有效期(分钟),120 = 2 小时 |
RefreshExpires | int | Refresh Token 有效期(分钟),1440 = 1 天 |
配置示例
json
{
"JwtConfig": {
"issuer": "admin.core",
"audience": "admin.core",
"securityKey": "73A74C69E2CF4522A7C69375CA0354D8",
"expires": 120,
"refreshExpires": 1440
}
}EmailConfig 邮件配置
配置文件:
Configs/appsettings.json中的
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
Host | string | SMTP 主机,如 smtp.qq.com |
Port | int | 端口号,如 465、587、25 |
UseSsl | bool | 是否使用 SSL |
UserName | string | 邮箱账号 |
Password | string | 邮箱密码 |
FromEmail | object | 发件人信息 |
FromEmail.Name | string | 发件人名称 |
FromEmail.Address | string | 发件人地址 |
ToEmail | object | 收件人信息 |
ToEmail.Name | string | 收件人名称 |
ToEmail.Address | string | 收件人地址 |
配置示例
json
{
"Email": {
"Host": "smtp.qq.com",
"Port": 465,
"UseSsl": true,
"UserName": "",
"Password": "",
"FromEmail": {
"Name": "",
"Address": ""
},
"ToEmail": {
"Name": "",
"Address": ""
}
}
}OSSConfig OSS 文件上传配置
配置文件:
Configs/ossconfig.json
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
LocalUploadConfig | object | 本地上传配置 |
LocalUploadConfig.Directory | string | 上传目录 |
LocalUploadConfig.DateTimeDirectory | string | 日期目录格式,如 yyyy/MM/dd |
LocalUploadConfig.Md5 | bool | 是否启用 MD5 校验 |
LocalUploadConfig.MaxSize | long | 文件最大大小(bytes) |
LocalUploadConfig.IncludeExtension | string[] | 包含文件扩展名列表 |
LocalUploadConfig.ExcludeExtension | string[] | 排除文件扩展名列表,如 [ ".exe", ".dll", ".jar" ] |
Provider | string | 默认文件存储供应商 |
OSSConfigs | object[] | OSS 配置列表 |
支持 Provider:Minio、Aliyun、QCloud(腾讯云)、Qiniu(七牛)、HuaweiCloud(华为云)。
每个 OSS 配置项说明:
| 配置项 | 类型 | 说明 |
|---|---|---|
Provider | string | 供应商类型 |
Endpoint | string | 端点地址 |
Region | string | 区域 |
AccessKey | string | 访问密钥 |
SecretKey | string | 密钥 |
IsEnableHttps | bool | 是否启用 HTTPS |
IsEnableCache | bool | 是否启用缓存 |
BucketName | string | 存储桶名称 |
Url | string | 文件外链地址 |
Md5 | bool | 是否启用 MD5 校验 |
Enable | bool | 是否启用 |
配置示例
json
{
"OssConfig": {
"LocalUploadConfig": {
"Directory": "upload",
"DateTimeDirectory": "yyyy/MM/dd",
"Md5": false,
"MaxSize": 104857600,
"IncludeExtension": [],
"ExcludeExtension": [ ".exe", ".dll", ".jar" ]
},
"Provider": "Minio",
"OSSConfigs": [
{
"Provider": "Minio",
"Endpoint": "127.0.0.1:9006",
"Region": "",
"AccessKey": "minio",
"SecretKey": "minio",
"IsEnableHttps": false,
"IsEnableCache": true,
"BucketName": "admin",
"Url": "",
"Md5": false,
"Enable": false
}
]
}
}RpcConfig 远程过程调用配置
配置文件:
Configs/appsettings.json中的RpcConfig节点
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
Http | object | Http 远程配置 |
Http.Enable | bool | 启用 Http 远程调用,默认 true |
Http.AssemblyNames | string[] | 客户端程序集名称列表,未配置将自动包含 ZhonTai.Admin.Contracts |
Grpc | object | Grpc 远程配置 |
Grpc.Enable | bool | 启用 Grpc 远程调用,默认 true |
Grpc.AssemblyNames | string[] | 客户端程序集名称列表,未配置将自动包含 ZhonTai.Admin.Core |
Grpc.ServerAssemblyNames | string[] | 服务端程序集名称列表 |
Endpoints | object[] | 远程地址列表 |
Endpoints[].Name | string | 模块名称,如 admin |
Endpoints[].HttpUrl | string | Http 请求地址,如 http://localhost:18010 |
Endpoints[].GrpcUrl | string | Grpc 请求地址,如 http://localhost:18011 |
配置示例
json
{
"RpcConfig": {
"Http": {
"Enable": true,
"AssemblyNames": [ "ZhonTai.Admin.Contracts" ]
},
"Grpc": {
"Enable": true,
"AssemblyNames": [ "ZhonTai.Admin.Core" ],
"ServerAssemblyNames": [ "ZhonTai.Admin" ]
},
"Endpoints": [
{
"Name": "admin",
"HttpUrl": "http://localhost:18010",
"GrpcUrl": "http://localhost:18011"
}
]
}
}ImConfig 即时通讯配置
配置文件:
Configs/appsettings.json中的ImConfig节点
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
Enable | bool | 启用即时通讯,默认 false |
Servers | string[] | IM 服务器集群地址列表,如 [ "127.0.0.1:17010" ] |
Server | string | WebSocket 业务端地址,如 ws://127.0.0.1:17010 |
RedisConnectionString | string | Redis 连接字符串,如 127.0.0.1:6379,password=,defaultDatabase=6 |
配置示例
json
{
"ImConfig": {
"Enable": false,
"Servers": [ "127.0.0.1:17010" ],
"Server": "ws://127.0.0.1:17010",
"RedisConnectionString": "127.0.0.1:6379,password=,defaultDatabase=6"
}
}TaskSchedulerConfig 任务调度配置
配置文件:
Configs/appsettings.json中的TaskScheduler节点
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
ProcessStartInfo | object | 进程启动信息 |
ProcessStartInfo.FileName | string | 应用程序路径,如 C:/grpcurl_1.8.7/grpcurl |
ProcessStartInfo.WorkingDirectory | string | 工作目录 |
AlerEmail | object | 告警邮件配置 |
AlerEmail.Enable | bool | 启用告警邮件 |
AlerEmail.Address | string | 告警邮件地址 |
Modules | object[] | 模块列表 |
Modules[].Name | string | 模块名称,如 admin |
Modules[].HttpUrl | string | Http 请求地址,如 http://localhost:18010 |
Modules[].GrpcUrl | string | Grpc 请求地址,如 http://localhost:18011 |
配置示例
json
{
"TaskScheduler": {
"ProcessStartInfo": {
"FileName": "C:/grpcurl_1.8.7/grpcurl",
"WorkingDirectory": ""
},
"AlerEmail": {
"Enable": true,
"Address": ""
},
"Modules": [
{
"Name": "admin",
"HttpUrl": "http://localhost:18010",
"GrpcUrl": "http://localhost:18011"
}
]
}
}RateLimitConfig 限流配置
配置文件:
Configs/ratelimitconfig.json
配置说明
| 配置项 | 类型 | 说明 |
|---|---|---|
Enable | bool | 启用限流 |
Method | string | 限流方式:Client(客户端限流)/ Ip(IP 限流) |
ClientIdType | string | 客户端 ID 类型:Token / UserId / ClientIdHeader |
CachePrefix | string | 缓存前缀 |
IpRateLimiting | object | IP 限流配置 |
IpRateLimiting.EnableEndpointRateLimiting | bool | 启用端点限流 |
IpRateLimiting.StackBlockedRequests | bool | 堆叠被阻止的请求 |
IpRateLimiting.RealIpHeader | string | 真实 IP 请求头 |
IpRateLimiting.IpWhitelist | string[] | IP 白名单 |
IpRateLimiting.EndpointWhitelist | string[] | 端点白名单 |
IpRateLimiting.ClientWhitelist | string[] | 客户端白名单 |
IpRateLimiting.HttpStatusCode | int | 限制时的 HTTP 状态码 |
IpRateLimiting.QuotaExceededResponse | object | 超出配额的响应内容 |
IpRateLimiting.GeneralRules | object[] | 通用限流规则 |
ClientRateLimiting | object | 客户端限流配置 |
ClientRateLimiting.EnableEndpointRateLimiting | bool | 启用端点限流 |
ClientRateLimiting.ClientIdHeader | string | 客户端 ID 请求头 |
ClientRateLimiting.IpWhitelist | string[] | IP 白名单 |
ClientRateLimiting.EndpointWhitelist | string[] | 端点白名单 |
ClientRateLimiting.ClientWhitelist | string[] | 客户端白名单 |
ClientRateLimiting.HttpStatusCode | int | 限制时的 HTTP 状态码 |
ClientRateLimiting.QuotaExceededResponse | object | 超出配额的响应内容 |
ClientRateLimiting.GeneralRules | object[] | 通用限流规则 |
配置示例
json
{
"RateLimitConfig": {
"Enable": false,
"Method": "Client",
"ClientIdType": "Token",
"CachePrefix": "zhontai:ratelimit",
"IpRateLimiting": {
"EnableEndpointRateLimiting": true,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"IpWhitelist": [],
"EndpointWhitelist": [
"get:/api/admin/auth/refresh",
"*:/*.*GrpcService/*"
],
"ClientWhitelist": [],
"HttpStatusCode": 429,
"QuotaExceededResponse": {
"Content": "{\"code\":429,\"msg\":\"访问过于频繁!\",\"success\": false}",
"ContentType": "application/json; charset=utf-8",
"StatusCode": 429
},
"GeneralRules": [
{
"Endpoint": "*:/api/*",
"Period": "1s",
"Limit": 3
},
{
"Endpoint": "*:/api/*",
"Period": "10m",
"Limit": 200
}
]
},
"ClientRateLimiting": {
"EnableEndpointRateLimiting": true,
"ClientIdHeader": "X-ClientId",
"IpWhitelist": [],
"EndpointWhitelist": [
"get:/api/admin/auth/refresh",
"*:/*.*GrpcService/*"
],
"ClientWhitelist": [],
"HttpStatusCode": 429,
"QuotaExceededResponse": {
"Content": "{\"code\":429,\"msg\":\"访问过于频繁!\",\"success\": false}",
"ContentType": "application/json; charset=utf-8",
"StatusCode": 429
},
"GeneralRules": [
{
"Endpoint": "*:/api/*",
"Period": "1s",
"Limit": 3
},
{
"Endpoint": "*:/api/*",
"Period": "10m",
"Limit": 200
}
]
}
}
}