From 62065457c4f1536e66312212bcaec8f58e34f570 Mon Sep 17 00:00:00 2001 From: JianWeie Date: Wed, 28 Sep 2022 10:51:41 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=A1=B9=E7=9B=AE=E5=A4=9A=E4=B8=AA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E4=B8=BAgb2312=EF=BC=8C=E5=AF=BC=E8=87=B4vs?= =?UTF-8?q?=20code=E6=88=96=E8=80=85mac=E4=B8=8B=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E4=B9=B1=E7=A0=81=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreCms.Net.Web.Admin/Program.cs | 26 +++---- CoreCms.Net.Web.Admin/Startup.cs | 108 +++++++++++++------------- CoreCms.Net.Web.WebApi/Program.cs | 24 +++--- CoreCms.Net.Web.WebApi/Startup.cs | 124 +++++++++++++++--------------- 4 files changed, 141 insertions(+), 141 deletions(-) diff --git a/CoreCms.Net.Web.Admin/Program.cs b/CoreCms.Net.Web.Admin/Program.cs index 818d960f..a14996b8 100644 --- a/CoreCms.Net.Web.Admin/Program.cs +++ b/CoreCms.Net.Web.Admin/Program.cs @@ -1,4 +1,4 @@ -using Autofac.Extensions.DependencyInjection; +using Autofac.Extensions.DependencyInjection; using CoreCms.Net.Loging; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -11,12 +11,12 @@ using System; namespace CoreCms.Net.Web.Admin { /// - /// ʼ + /// 初始化 /// public class Program { /// - /// + /// 启动配置 /// /// public static void Main(string[] args) @@ -24,24 +24,24 @@ namespace CoreCms.Net.Web.Admin var host = CreateHostBuilder(args).Build(); try { - //ȷNLog.configַappsettings.jsonͬ + //确保NLog.config中连接字符串与appsettings.json中同步 NLogUtil.EnsureNlogConfig("NLog.config"); - //throw new Exception("쳣");//for test - //ĿʱҪ - NLogUtil.WriteAll(NLog.LogLevel.Trace, LogType.Web, "վ", "վɹ"); + //throw new Exception("测试异常");//for test + //其他项目启动时需要做的事情 + NLogUtil.WriteAll(NLog.LogLevel.Trace, LogType.Web, "网站启动", "网站启动成功"); host.Run(); } catch (Exception ex) { - //ʹnlogд־ļһݿû/ӳɹ - NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.Web, "վ", "ʼ쳣", ex); + //使用nlog写到本地日志文件(万一数据库没创建/连接成功) + NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.Web, "网站启动", "初始化数据异常", ex); throw; } } /// - /// ֧ + /// 创建启动支撑 /// /// /// @@ -50,8 +50,8 @@ namespace CoreCms.Net.Web.Admin .UseServiceProviderFactory(new AutofacServiceProviderFactory()) //<--NOTE THIS .ConfigureLogging(logging => { - logging.ClearProviders(); //ƳѾע־ - logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); //С־ + logging.ClearProviders(); //移除已经注册的其他日志处理程序 + logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); //设置最小的日志级别 }) .UseNLog() //NLog: Setup NLog for Dependency injection .ConfigureWebHostDefaults(webBuilder => @@ -59,7 +59,7 @@ namespace CoreCms.Net.Web.Admin webBuilder .ConfigureKestrel(serverOptions => { - serverOptions.AllowSynchronousIO = true;//ͬ IO + serverOptions.AllowSynchronousIO = true;//启用同步 IO }) .UseStartup(); }); diff --git a/CoreCms.Net.Web.Admin/Startup.cs b/CoreCms.Net.Web.Admin/Startup.cs index 826c79ec..eac89ce6 100644 --- a/CoreCms.Net.Web.Admin/Startup.cs +++ b/CoreCms.Net.Web.Admin/Startup.cs @@ -1,4 +1,4 @@ - + using System.Linq; using Autofac; using CoreCms.Net.Auth; @@ -30,12 +30,12 @@ using Yitter.IdGenerator; namespace CoreCms.Net.Web.Admin { /// - /// + /// 启动配置 /// public class Startup { /// - /// 캯 + /// 构造函数 /// /// /// @@ -59,108 +59,108 @@ namespace CoreCms.Net.Web.Admin /// public void ConfigureServices(IServiceCollection services) { - //ӱ·ȡ֧ + //添加本地路径获取支持 services.AddSingleton(new AppSettingsHelper(Env.ContentRootPath)); services.AddSingleton(new LogLockHelper(Env.ContentRootPath)); - //Memory + //Memory缓存 services.AddMemoryCacheSetup(); - //Redis + //Redis缓存 services.AddRedisCacheSetup(); - //ݿSqlSugarע֧ + //添加数据库连接SqlSugar注入支持 services.AddSqlSugarSetup(); - //ÿCORS + //配置跨域(CORS) services.AddCorsSetup(); - //session֧(sessioncacheд洢) + //添加session支持(session依赖于cache进行存储) services.AddSession(); - // AutoMapper֧ + // AutoMapper支持 services.AddAutoMapper(typeof(AutoMapperConfiguration)); - //ʹ SignalR + //使用 SignalR services.AddSignalR(); - // Payment ע(֧֧/΢֧) + // 引入Payment 依赖注入(支付宝支付/微信支付) services.AddAlipay(); services.AddWeChatPay(); - // appsettings.json ѡ - //עԶ֧ļ潫ȡʹPaylinkֱ߽ӿԶ崦 + // 在 appsettings.json 中 配置选项 + //注册自定义的支付配置文件,后面将取消使用Paylink,直接走接口请求自定义处理。 services.Configure(Configuration.GetSection("WeChatPay")); services.Configure(Configuration.GetSection("Alipay")); - //עԶ΢Žӿļ + //注册自定义微信接口配置文件 services.Configure(Configuration.GetSection(nameof(WeChat.Service.Options.WeChatOptions))); - // ע빤 HTTP ͻ + // 注入工厂 HTTP 客户端 services.AddHttpClient(); services.AddSingleton(); - //ÿͻIP + //启用客户端IP限制速率 services.AddIpPolicyRateLimitSetup(Configuration); - //Swaggerӿĵע + //Swagger接口文档注入 services.AddAdminSwaggerSetup(); - //jwtȨ֧ע + //jwt授权支持注入 services.AddAuthorizationSetupForAdmin(); - //ע + //上下文注入 services.AddHttpContextSetup(); - //мAutoFac滻 + //服务配置中加入AutoFac控制器替换规则。 services.Replace(ServiceDescriptor.Transient()); - //עmvcעrazorͼ + //注册mvc,注册razor引擎视图 services.AddMvc(options => { - //ʵ֤ + //实体验证 options.Filters.Add(); - //쳣 + //异常处理 options.Filters.Add(); - //Swagger޳Ҫapiչʾб + //Swagger剔除不需要加入api展示的列表 options.Conventions.Add(new ApiExplorerIgnores()); options.EnableEndpointRouting = false; }) .AddNewtonsoftJson(p => { - //ݸʽĸСд ʹշ + //数据格式首字母小写 不使用驼峰 p.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - //ʹշʽkey + //不使用驼峰样式的key //p.SerializerSettings.ContractResolver = new DefaultContractResolver(); - //ѭ + //忽略循环引用 p.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; - //ʱʽ + //设置时间格式 p.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; }); - // ѩƯ㷨 - // IdGeneratorOptions ڹ캯 WorkerId + // 雪花漂移算法 + // 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId: var options = new IdGeneratorOptions(1); - // WorkerIdBitLength Ĭֵ6ֵ֧ WorkerId ֵΪ2^6-1 WorkerId 64ø WorkerIdBitLength + // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength // options.WorkerIdBitLength = 10; - // ...... òο IdGeneratorOptions 壬һ˵ֻҪ WorkerIdBitLength WorkerId ֵ + // ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。 - // IJöЧ + // 保存参数(必须的操作,否则以上设置都不能生效): YitIdHelper.SetIdGenerator(options); - // ʼԺ󣬼κҪIDĵط· + // 初始化以后,即可在任何需要生成ID的地方,调用以下方法: //var newId = YitIdHelper.NextId(); } /// - /// Autofac + /// Autofac规则配置 /// /// public void ConfigureContainer(ContainerBuilder builder) { builder.RegisterModule(new AutofacModuleRegister()); - //ȡпͲʹע + //获取所有控制器类型并使用属性注入 var controllerBaseType = typeof(ControllerBase); builder.RegisterAssemblyTypes(typeof(Program).Assembly) .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType) @@ -174,20 +174,20 @@ namespace CoreCms.Net.Web.Admin /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - #region Ubuntu Nginx ܻȡIP + #region 解决Ubuntu Nginx 代理不能获取IP问题 app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); #endregion - // Ip + // 开启Ip限流 app.UseIpLimitMiddle(); - // ¼뷵 (ע⿪ȨޣȻ޷д) + // 记录请求与返回数据 (注意开启权限,不然本地无法写入) app.UseRequestResponseLog(); - // ûʼ¼(ŵ㣬Ȼ쳣ᱨΪܷ)(ע⿪ȨޣȻ޷д) + // 用户访问记录(必须放到外层,不然如果遇到异常,会报错,因为不能返回流)(注意开启权限,不然本地无法写入) app.UseRecordAccessLogsMildd(GlobalEnumVars.CoreShopSystemCategory.Admin.ToString()); - // ¼ip (ע⿪ȨޣȻ޷д) + // 记录ip请求 (注意开启权限,不然本地无法写入) app.UseIpLogMildd(); // signalr app.UseSignalRSendMildd(); @@ -195,7 +195,7 @@ namespace CoreCms.Net.Web.Admin app.UseSwagger().UseSwaggerUI(c => { - //ݰ汾Ƶ չʾ + //根据版本名称倒序 遍历展示 typeof(CustomApiVersion.ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach( version => { @@ -204,12 +204,12 @@ namespace CoreCms.Net.Web.Admin c.RoutePrefix = "doc"; }); - //ʹ Session + //使用 Session app.UseSession(); if (env.IsDevelopment()) { - // ڿУʹ쳣ҳ棬Ա¶ջϢԲҪ + // 在开发环境中,使用异常页面,这样可以暴露错误堆栈信息,所以不要放在生产环境。 app.UseDeveloperExceptionPage(); } else @@ -219,21 +219,21 @@ namespace CoreCms.Net.Web.Admin app.UseHsts(); } - // CORS + // CORS跨域 app.UseCors(AppSettingsConstVars.CorsPolicyName); - // תhttps + // 跳转https //app.UseHttpsRedirection(); - // ʹþ̬ļ + // 使用静态文件 app.UseStaticFiles(); - // ʹcookie + // 使用cookie app.UseCookiePolicy(); - // ش + // 返回错误码 app.UseStatusCodePages(); // Routing app.UseRouting(); - // ȿ֤ + // 先开启认证 app.UseAuthentication(); - // ȻȨм + // 然后是授权中间件 app.UseAuthorization(); app.UseEndpoints(endpoints => { @@ -247,8 +247,8 @@ namespace CoreCms.Net.Web.Admin "{controller=Home}/{action=Index}/{id?}"); }); - //Ĭʼҳdefault.html - //˴·wwwrootļе· + //设置默认起始页(如default.html) + //此处的路径是相对于wwwroot文件夹的相对路径 var defaultFilesOptions = new DefaultFilesOptions(); defaultFilesOptions.DefaultFileNames.Clear(); defaultFilesOptions.DefaultFileNames.Add("index.html"); diff --git a/CoreCms.Net.Web.WebApi/Program.cs b/CoreCms.Net.Web.WebApi/Program.cs index bdeb09b2..a2ade68f 100644 --- a/CoreCms.Net.Web.WebApi/Program.cs +++ b/CoreCms.Net.Web.WebApi/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using Autofac.Extensions.DependencyInjection; using CoreCms.Net.Loging; using Microsoft.AspNetCore.Hosting; @@ -12,12 +12,12 @@ using LogLevel = NLog.LogLevel; namespace CoreCms.Net.Web.WebApi { /// - /// + /// 启动类 /// public class Program { /// - /// + /// 启动配置 /// /// public static void Main(string[] args) @@ -25,23 +25,23 @@ namespace CoreCms.Net.Web.WebApi var host = CreateHostBuilder(args).Build(); try { - //ȷNLog.configַappsettings.jsonͬ + //确保NLog.config中连接字符串与appsettings.json中同步 NLogUtil.EnsureNlogConfig("NLog.config"); - //ĿʱҪ - NLogUtil.WriteAll(LogLevel.Trace, LogType.Web, "ӿ", "ӿɹ"); + //其他项目启动时需要做的事情 + NLogUtil.WriteAll(LogLevel.Trace, LogType.Web, "接口启动", "接口启动成功"); host.Run(); } catch (Exception ex) { - //ʹnlogд־ļһݿû/ӳɹ - NLogUtil.WriteFileLog(LogLevel.Error, LogType.ApiRequest, "ӿ", "ʼ쳣", ex); + //使用nlog写到本地日志文件(万一数据库没创建/连接成功) + NLogUtil.WriteFileLog(LogLevel.Error, LogType.ApiRequest, "接口启动", "初始化数据异常", ex); throw; } } /// - /// ֧ + /// 创建启动支撑 /// /// /// @@ -51,8 +51,8 @@ namespace CoreCms.Net.Web.WebApi .UseServiceProviderFactory(new AutofacServiceProviderFactory()) //<--NOTE THIS .ConfigureLogging(logging => { - logging.ClearProviders(); //ƳѾע־ - logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); //С־ + logging.ClearProviders(); //移除已经注册的其他日志处理程序 + logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); //设置最小的日志级别 }) .UseNLog() //NLog: Setup NLog for Dependency injection .ConfigureWebHostDefaults(webBuilder => @@ -60,7 +60,7 @@ namespace CoreCms.Net.Web.WebApi webBuilder .ConfigureKestrel(serverOptions => { - serverOptions.AllowSynchronousIO = true; //ͬ IO + serverOptions.AllowSynchronousIO = true; //启用同步 IO }) .UseStartup(); }); diff --git a/CoreCms.Net.Web.WebApi/Startup.cs b/CoreCms.Net.Web.WebApi/Startup.cs index 9f63ab18..4bde1c62 100644 --- a/CoreCms.Net.Web.WebApi/Startup.cs +++ b/CoreCms.Net.Web.WebApi/Startup.cs @@ -1,4 +1,4 @@ -using Autofac; +using Autofac; using CoreCms.Net.Auth; using CoreCms.Net.Configuration; using CoreCms.Net.Core.AutoFac; @@ -34,12 +34,12 @@ using Yitter.IdGenerator; namespace CoreCms.Net.Web.WebApi { /// - /// + /// 启动配置 /// public class Startup { /// - /// 캯 + /// 构造函数 /// /// /// @@ -49,125 +49,125 @@ namespace CoreCms.Net.Web.WebApi Env = env; } /// - /// + /// 配置属性 /// public IConfiguration Configuration { get; } /// - /// web + /// web环境 /// public IWebHostEnvironment Env { get; } /// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - //ӱ·ȡ֧ + //添加本地路径获取支持 services.AddSingleton(new AppSettingsHelper(Env.ContentRootPath)); services.AddSingleton(new LogLockHelper(Env.ContentRootPath)); - //Memory + //Memory缓存 services.AddMemoryCacheSetup(); - //Redis + //Redis缓存 services.AddRedisCacheSetup(); - //ݿSqlSugarע֧ + //添加数据库连接SqlSugar注入支持 services.AddSqlSugarSetup(); - //ÿCORS + //配置跨域(CORS) services.AddCorsSetup(); - //session֧(sessioncacheд洢) + //添加session支持(session依赖于cache进行存储) services.AddSession(); - // AutoMapper֧ + // AutoMapper支持 services.AddAutoMapper(typeof(AutoMapperConfiguration)); - //MediatRֻҪעһ,ͬĿ¾ͲҪע + //MediatR(只需要注册一个,同项目或类库下就不需要注册多个) services.AddMediatR(typeof(TextMessageEventCommand).Assembly); - //ʹ SignalR + //使用 SignalR services.AddSignalR(); - //RedisϢ + //Redis消息队列 services.AddRedisMessageQueueSetup(); - // Payment ע(֧֧/΢֧) + // 引入Payment 依赖注入(支付宝支付/微信支付) services.AddAlipay(); services.AddWeChatPay(); - // appsettings.json ѡ + // 在 appsettings.json 中 配置选项 services.Configure(Configuration.GetSection("WeChatPay")); services.Configure(Configuration.GetSection("Alipay")); - //עԶ΢Žӿļ + //注册自定义微信接口配置文件 services.Configure(Configuration.GetSection(nameof(WeChat.Service.Options.WeChatOptions))); - // ע빤 HTTP ͻ + // 注入工厂 HTTP 客户端 services.AddHttpClient(); services.AddSingleton(); - //ÿͻIP + //启用客户端IP限制速率 services.AddIpPolicyRateLimitSetup(Configuration); - //Swaggerӿĵע + //Swagger接口文档注入 services.AddClientSwaggerSetup(); - //עHangfireʱ + //注册Hangfire定时任务 services.AddHangFireSetup(); - //Ȩ֧ע + //授权支持注入 services.AddAuthorizationSetupForClient(); - //ע + //上下文注入 services.AddHttpContextSetup(); - //мAutoFac滻 + //服务配置中加入AutoFac控制器替换规则。 services.Replace(ServiceDescriptor.Transient()); - //עmvcעrazorͼ + //注册mvc,注册razor引擎视图 services.AddMvc(options => { - //ʵ֤ + //实体验证 options.Filters.Add(); - //쳣 + //异常处理 options.Filters.Add(); - //Swagger޳Ҫapiչʾб + //Swagger剔除不需要加入api展示的列表 options.Conventions.Add(new ApiExplorerIgnores()); }) .AddNewtonsoftJson(p => { - //ݸʽĸСд ʹôշ + //数据格式首字母小写 不使用大驼峰 p.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - //ʹշʽkey + //不使用驼峰样式的key //p.SerializerSettings.ContractResolver = new DefaultContractResolver(); - //ѭ + //忽略循环引用 p.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; - //ʱʽʹyyyy/MM/ddʽΪiosϵͳ֧2018-03-29ʽʱ䣬ֻʶ2018/03/09ָʽ + //设置时间格式(必须使用yyyy/MM/dd格式,因为ios系统不支持2018-03-29格式的时间,只识别2018/03/09这种格式。) p.SerializerSettings.DateFormatString = "yyyy/MM/dd HH:mm:ss"; }); - // ѩƯ㷨 - // IdGeneratorOptions ڹ캯 WorkerId + // 雪花漂移算法 + // 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId: var options = new IdGeneratorOptions(1); - // WorkerIdBitLength Ĭֵ6ֵ֧ WorkerId ֵΪ2^6-1 WorkerId 64ø WorkerIdBitLength + // WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength // options.WorkerIdBitLength = 10; - // ...... òο IdGeneratorOptions 壬һ˵ֻҪ WorkerIdBitLength WorkerId ֵ + // ...... 其它参数设置参考 IdGeneratorOptions 定义,一般来说,只要再设置 WorkerIdBitLength (决定 WorkerId 的最大值)。 - // IJöЧ + // 保存参数(必须的操作,否则以上设置都不能生效): YitIdHelper.SetIdGenerator(options); - // ʼԺ󣬼κҪIDĵط· + // 初始化以后,即可在任何需要生成ID的地方,调用以下方法: //var newId = YitIdHelper.NextId(); } /// - /// Autofac + /// Autofac规则配置 /// /// public void ConfigureContainer(ContainerBuilder builder) { - //ȡпͲʹע + //获取所有控制器类型并使用属性注入 var controllerBaseType = typeof(ControllerBase); builder.RegisterAssemblyTypes(typeof(Program).Assembly) .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType) @@ -185,43 +185,43 @@ namespace CoreCms.Net.Web.WebApi /// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - #region Ubuntu Nginx ܻȡIP + #region 解决Ubuntu Nginx 代理不能获取IP问题 app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); #endregion - // Ip + // 开启Ip限流 app.UseIpLimitMiddle(); - // ¼뷵 (ע⿪ȨޣȻ޷д) + // 记录请求与返回数据 (注意开启权限,不然本地无法写入) app.UseRequestResponseLog(); - // ûʼ¼(ŵ㣬Ȼ쳣ᱨΪܷ)(ע⿪ȨޣȻ޷д) + // 用户访问记录(必须放到外层,不然如果遇到异常,会报错,因为不能返回流)(注意开启权限,不然本地无法写入) app.UseRecordAccessLogsMildd(GlobalEnumVars.CoreShopSystemCategory.Api.ToString()); - // ¼ip (ע⿪ȨޣȻ޷д) + // 记录ip请求 (注意开启权限,不然本地无法写入) app.UseIpLogMildd(); - //ǿʾ + //强制显示中文 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); app.UseSwagger().UseSwaggerUI(c => { - //ݰ汾Ƶ չʾ + //根据版本名称倒序 遍历展示 typeof(CustomApiVersion.ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach( version => { c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"Doc {version}"); }); - //Ĭתswagger-ui + //设置默认跳转到swagger-ui c.RoutePrefix = "doc"; //c.RoutePrefix = string.Empty; }); - #region Hangfireʱ + #region Hangfire定时任务 - //Ȩ + //授权 var filter = new BasicAuthAuthorizationFilter( new BasicAuthAuthorizationFilterOptions { @@ -242,8 +242,8 @@ namespace CoreCms.Net.Web.WebApi }); var options = new DashboardOptions { - AppPath = "/",//ʱתĵַ - DisplayStorageConnectionString = false,//ǷʾݿϢ + AppPath = "/",//返回时跳转的地址 + DisplayStorageConnectionString = false,//是否显示数据库连接信息 Authorization = new[] { filter @@ -251,17 +251,17 @@ namespace CoreCms.Net.Web.WebApi IsReadOnlyFunc = _ => false }; - app.UseHangfireDashboard("/job", options); //ԸıDashboardurl + app.UseHangfireDashboard("/job", options); //可以改变Dashboard的url HangfireDispose.HangfireService(); #endregion - //ʹ Session + //使用 Session app.UseSession(); if (env.IsDevelopment()) { - // ڿУʹ쳣ҳ棬Ա¶ջϢԲҪ + // 在开发环境中,使用异常页面,这样可以暴露错误堆栈信息,所以不要放在生产环境。 app.UseDeveloperExceptionPage(); } else @@ -271,17 +271,17 @@ namespace CoreCms.Net.Web.WebApi app.UseHsts(); } - // CORS + // CORS跨域 app.UseCors(AppSettingsConstVars.CorsPolicyName); // Routing app.UseRouting(); - // ʹþ̬ļ + // 使用静态文件 app.UseStaticFiles(); - // ȿ֤ + // 先开启认证 app.UseAuthentication(); - // ȻȨм + // 然后是授权中间件 app.UseAuthorization(); app.UseEndpoints(endpoints => @@ -299,8 +299,8 @@ namespace CoreCms.Net.Web.WebApi - //Ĭʼҳdefault.html - //˴·wwwrootļе· + //设置默认起始页(如default.html) + //此处的路径是相对于wwwroot文件夹的相对路径 var defaultFilesOptions = new DefaultFilesOptions(); defaultFilesOptions.DefaultFileNames.Clear(); defaultFilesOptions.DefaultFileNames.Add("index.html");