/// <summary> /// 定义全局服务 /// </summary> /// <param name="p_services"></param> /// <returns></returns> public IServiceProvider ConfigureServices(IServiceCollection p_services) { // 配置 KestrelServer p_services.Configure <KestrelServerOptions>(options => { // 未使用Listen方法,因无法应用外部设置的端口! options.ConfigureEndpointDefaults(listenOptions => { // 浏览器要求http2.0协议必须采用https通信,http2.0协议和https之间本来没有依赖关系! // 默认http2 listenOptions.Protocols = HttpProtocols.Http2; // 为Kestrel加载X509证书,证书名称tls.pfx,位置在根目录,默认证书为localhost,生成环境可替换 var tls = new FileInfo(Path.Combine(AppContext.BaseDirectory, "tls.pfx")); if (tls.Exists) { using (var stream = tls.OpenRead()) { byte[] pfx = new byte[tls.Length]; stream.Read(pfx, 0, (int)stream.Length); listenOptions.UseHttps(new X509Certificate2(pfx, "dt")); } } else { Log.Error("Kestrel缺少X509证书文件tls.pfx"); } }); // 不限制请求/响应的速率,不适合流模式长时间等待的情况! options.Limits.MinRequestBodyDataRate = null; options.Limits.MinResponseDataRate = null; long maxSize = Kit.GetCfg <long>("MaxRequestBodySize", 0); if (maxSize > 0) { // 设置post的body的最大长度,默认28.6M options.Limits.MaxRequestBodySize = maxSize; } Log.Information("启动 KestrelServer 成功"); }); // 配置 IISHttpServer p_services.Configure <IISServerOptions>(options => { long maxSize = Kit.GetCfg <long>("MaxRequestBodySize", 0); if (maxSize > 0) { // 设置post的body的最大长度,默认28.6M // web.config 和 service.json都需设置 options.MaxRequestBodySize = maxSize; } Log.Information("启动 IISHttpServer 成功"); }); Kit.ConfigureServices(p_services); return(Silo.ConfigureServices(p_services)); }
/// <summary> /// 缓存Sql串 /// </summary> public static void CacheSql() { if (Kit.GetCfg("CacheSql", true)) { Kit.Sql = GetDictSql; LoadCacheSql(); } else { Kit.Sql = GetDebugSql; Log.Information("未缓存Sql, 调试状态"); } }
/// <summary> /// 系统配置(json文件)修改事件 /// </summary> public static void OnConfigChanged() { if (Kit.GetCfg("CacheSql", true)) { Kit.Sql = GetDictSql; LoadCacheSql(); Log.Information("切换到Sql缓存模式"); } else if (Kit.Sql != GetDictSql) { if (Kit.Sql != GetDebugSql) { Kit.Sql = GetDebugSql; Log.Information("切换到Sql调试模式"); } } }