From 9fc5162230f08d512fa387e18264fe60a17183ef Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Wed, 30 Oct 2019 17:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=A1=B9=E7=9B=AE=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=88=B0.net=20core=203.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.API/COMCMS.API.csproj | 2 +- COMCMS.Common/COMCMS.Common.csproj | 9 ++- COMCMS.Common/ThumbnailHelper.cs | 4 +- COMCMS.Core/COMCMS.Core.csproj | 4 +- COMCMS.Core/Core/管理员.Biz.cs | 40 +++++----- .../AdminCP/Controllers/IndexController.cs | 4 +- .../AdminCP/Controllers/LoginController.cs | 4 +- .../AdminCP/Controllers/SystemController.cs | 4 +- .../AdminCP/Controllers/UploadController.cs | 7 +- .../AdminCP/Views/Article/AddArticle.cshtml | 2 +- COMCMS.Web/COMCMS.Web.csproj | 24 +++--- .../Common/HttpGlobalExceptionFilter.cs | 4 +- COMCMS.Web/Configuration/JsonOptionsConfig.cs | 2 +- COMCMS.Web/Program.cs | 13 ++-- COMCMS.Web/Startup.cs | 74 ++++++++++--------- README.md | 6 +- XCoder/Entity/Build.tt | 3 +- XCoder/XCoder(代码生成器).csproj | 8 +- XCoder/packages.config | 4 +- 19 files changed, 112 insertions(+), 106 deletions(-) diff --git a/COMCMS.API/COMCMS.API.csproj b/COMCMS.API/COMCMS.API.csproj index be684ba..d73cd76 100644 --- a/COMCMS.API/COMCMS.API.csproj +++ b/COMCMS.API/COMCMS.API.csproj @@ -1,7 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 diff --git a/COMCMS.Common/COMCMS.Common.csproj b/COMCMS.Common/COMCMS.Common.csproj index 64c5fa5..f7aeaf3 100644 --- a/COMCMS.Common/COMCMS.Common.csproj +++ b/COMCMS.Common/COMCMS.Common.csproj @@ -1,14 +1,15 @@  - netcoreapp2.2 + netcoreapp3.0 - - + + + - + diff --git a/COMCMS.Common/ThumbnailHelper.cs b/COMCMS.Common/ThumbnailHelper.cs index 0137a40..386dd00 100644 --- a/COMCMS.Common/ThumbnailHelper.cs +++ b/COMCMS.Common/ThumbnailHelper.cs @@ -22,11 +22,11 @@ namespace COMCMS.Common /// /// 程序绝对目录 /// - private static string _ContentRootPath = DI.ServiceProvider.GetService().ContentRootPath; + private static string _ContentRootPath = DI.ServiceProvider.GetService().ContentRootPath; /// /// 静态文件 /// - private static string _WebRootPath = DI.ServiceProvider.GetService().WebRootPath; + private static string _WebRootPath = DI.ServiceProvider.GetService().WebRootPath; #region 方式 public enum CutMode diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index a2c8c0a..3f8232b 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -1,11 +1,11 @@  - netcoreapp2.2 + netcoreapp3.0 - + diff --git a/COMCMS.Core/Core/管理员.Biz.cs b/COMCMS.Core/Core/管理员.Biz.cs index bdca1ad..ddf17f2 100644 --- a/COMCMS.Core/Core/管理员.Biz.cs +++ b/COMCMS.Core/Core/管理员.Biz.cs @@ -184,8 +184,8 @@ namespace COMCMS.Core { if (IsAdminLogin()) { - //return Find(_.UserName == SessionHelper.GetSession(sessionAdminNameKey).ToString()); - return Find(_.UserName == AuthenticationHelper.GetClaim(sessionAdminNameKey)); + return Find(_.UserName == SessionHelper.GetSession(sessionAdminNameKey).ToString()); + //return Find(_.UserName == AuthenticationHelper.GetClaim(sessionAdminNameKey)); } else @@ -241,8 +241,8 @@ namespace COMCMS.Core //写入Session 和 Cookies //SessionHelper.WriteSession("rtadminguid", GUID.ToString()); //CookiesHelper.WriteCookie("rtadminguid", GUID.ToString(), 120); - //SetAdminInfo(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt); - SetAdminInfoAsync(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt).Wait(); + SetAdminInfo(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt); + //SetAdminInfoAsync(entity.UserName, entity.PassWord, entity.Id, 0, "", GUID.ToString(), entity.Salt).Wait(); return true; } @@ -255,22 +255,22 @@ namespace COMCMS.Core /// 是否登录 public static bool IsAdminLogin() { - //string adminName = SessionHelper.GetSession(sessionAdminNameKey).ToString();//用户名 - //string adminID = SessionHelper.GetSession(sessionAdminIDKey).ToString();//ID - string adminName = AuthenticationHelper.GetClaim(sessionAdminNameKey);//用户名 - string adminID = AuthenticationHelper.GetClaim(sessionAdminIDKey);//ID + string adminName = SessionHelper.GetSession(sessionAdminNameKey).ToString();//用户名 + string adminID = SessionHelper.GetSession(sessionAdminIDKey).ToString();//ID + //string adminName = AuthenticationHelper.GetClaim(sessionAdminNameKey);//用户名 + //string adminID = AuthenticationHelper.GetClaim(sessionAdminIDKey);//ID //如果Session失效,则用Cookies判断 if (string.IsNullOrEmpty(adminName) || string.IsNullOrEmpty(adminID)) { - //string cooAdminName = CookiesHelper.GetCookie(cookiesAdminNameKey);//用户名 - //string cooAdminID = CookiesHelper.GetCookie(cookiesAdminIDKey);//ID - //string cooLoginInfo = CookiesHelper.GetCookie(cookiesAdminInfoKey);//信息 - //string cooAdminLogID = CookiesHelper.GetCookie(cookiesAdminLogIDKey);//日志GUID - string cooAdminName = AuthenticationHelper.GetClaim(cookiesAdminNameKey);//用户名 - string cooAdminID = AuthenticationHelper.GetClaim(cookiesAdminIDKey);//ID - string cooLoginInfo = AuthenticationHelper.GetClaim(cookiesAdminInfoKey);//信息 - string cooAdminLogID = AuthenticationHelper.GetClaim(cookiesAdminLogIDKey);//日志GUID + string cooAdminName = CookiesHelper.GetCookie(cookiesAdminNameKey);//用户名 + string cooAdminID = CookiesHelper.GetCookie(cookiesAdminIDKey);//ID + string cooLoginInfo = CookiesHelper.GetCookie(cookiesAdminInfoKey);//信息 + string cooAdminLogID = CookiesHelper.GetCookie(cookiesAdminLogIDKey);//日志GUID + //string cooAdminName = AuthenticationHelper.GetClaim(cookiesAdminNameKey);//用户名 + //string cooAdminID = AuthenticationHelper.GetClaim(cookiesAdminIDKey);//ID + //string cooLoginInfo = AuthenticationHelper.GetClaim(cookiesAdminInfoKey);//信息 + //string cooAdminLogID = AuthenticationHelper.GetClaim(cookiesAdminLogIDKey);//日志GUID if (string.IsNullOrEmpty(cooAdminID) || string.IsNullOrEmpty(cooAdminName) || string.IsNullOrEmpty(cooLoginInfo) || string.IsNullOrEmpty(cooAdminLogID)) { @@ -298,16 +298,16 @@ namespace COMCMS.Core } //重新写入Session 和 Cookies - //SetAdminInfo(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt); + SetAdminInfo(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt); - SetAdminInfoAsync(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt).Wait(); + //SetAdminInfoAsync(model.UserName, model.PassWord, model.Id, 0, "", cooAdminLogID, model.Salt).Wait(); return true; } else { - //ClearInfo();//清除信息 - ClearInfoAsync().Wait(); + ClearInfo();//清除信息 + //ClearInfoAsync().Wait(); return false;//信息错误 } } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs index a9cc8d0..1113862 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/IndexController.cs @@ -16,8 +16,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [Area("AdminCP")] public class IndexController : AdminBaseController { - private readonly IHostingEnvironment _env; - public IndexController(IHostingEnvironment env) + private readonly IWebHostEnvironment _env; + public IndexController(IWebHostEnvironment env) { _env = env; } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs index b4074f1..38bb7af 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs @@ -122,8 +122,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// public IActionResult Logout() { - //Admin.ClearInfo(); - Admin.ClearInfoAsync().Wait(); + Admin.ClearInfo(); + //Admin.ClearInfoAsync().Wait(); return Redirect("~/AdminCP/Login"); } #endregion diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs index 8c5da32..224fc6b 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/SystemController.cs @@ -19,8 +19,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [Area("AdminCP")] public class SystemController : AdminBaseController { - private IHostingEnvironment _env; - public SystemController(IHostingEnvironment env) + private IWebHostEnvironment _env; + public SystemController(IWebHostEnvironment env) { _env = env; } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs index 94aeb05..6fe4439 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs @@ -15,7 +15,6 @@ using COMCMS.Core.Models; using System.DrawingCore; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Internal; using Microsoft.Extensions.Primitives; using NewLife.UserGroup.WebUploader; @@ -47,9 +46,9 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers public class UploadController : AdminBaseController { private readonly SystemSetting _attachsetting; - private IHostingEnvironment _env; + private IWebHostEnvironment _env; private AttachConfigEntity attach; - public UploadController(IHostingEnvironment env, IOptions attachsetting) + public UploadController(IWebHostEnvironment env, IOptions attachsetting) { attach = Config.GetSystemConfig().AttachConfigEntity; _env = env; @@ -424,7 +423,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers var req = HttpContext.Request; var f = Request.Form.Files[0]; - Request.EnableRewind(); + //Request.EnableRewind(); Image image = null; using (StreamReader reader = new StreamReader(req.Body, Encoding.UTF8, true, 1024, true)) { diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml index 75cbdad..ec176f6 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml @@ -19,7 +19,7 @@ diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 5d346e0..4dfe261 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -1,22 +1,22 @@  - netcoreapp2.2 + netcoreapp3.0 - - - - - - + + + + + + - - - - - + + + + + diff --git a/COMCMS.Web/Common/HttpGlobalExceptionFilter.cs b/COMCMS.Web/Common/HttpGlobalExceptionFilter.cs index b32fff8..25944c5 100644 --- a/COMCMS.Web/Common/HttpGlobalExceptionFilter.cs +++ b/COMCMS.Web/Common/HttpGlobalExceptionFilter.cs @@ -12,8 +12,8 @@ namespace COMCMS.Web.Common { public class HttpGlobalExceptionFilter : IExceptionFilter { - readonly IHostingEnvironment _env; - public HttpGlobalExceptionFilter(IHostingEnvironment env) + readonly IWebHostEnvironment _env; + public HttpGlobalExceptionFilter(IWebHostEnvironment env) { _env = env; } diff --git a/COMCMS.Web/Configuration/JsonOptionsConfig.cs b/COMCMS.Web/Configuration/JsonOptionsConfig.cs index 94b1a6c..5b14718 100644 --- a/COMCMS.Web/Configuration/JsonOptionsConfig.cs +++ b/COMCMS.Web/Configuration/JsonOptionsConfig.cs @@ -10,7 +10,7 @@ namespace COMCMS.Web.Configuration { public class JsonOptionsConfig { - public static void ConfigJsonOptions(MvcJsonOptions options) + public static void ConfigJsonOptions(MvcNewtonsoftJsonOptions options) { var settings = options.SerializerSettings; //日期类型默认格式化处理 diff --git a/COMCMS.Web/Program.cs b/COMCMS.Web/Program.cs index 1559dfb..e5b5dda 100644 --- a/COMCMS.Web/Program.cs +++ b/COMCMS.Web/Program.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace COMCMS.Web @@ -14,12 +15,14 @@ namespace COMCMS.Web { public static void Main(string[] args) { - BuildWebHost(args).Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHost BuildWebHost(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - .Build(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } } diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index e3148f2..8d8417b 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -4,31 +4,28 @@ using System.Linq; using System.Text.Encodings.Web; using System.Text.Unicode; using System.Threading.Tasks; +using COMCMS.Common; +using COMCMS.Web.Common; +using COMCMS.Web.ExceptionHandler; +using COMCMS.Web.Models; +using Lib.Core.MiddlewareExtension.Extension; +using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.WebEncoders; -using Microsoft.AspNetCore.Mvc; -using COMCMS.Common; -using COMCMS.Web.Models; -using COMCMS.Web.Common; -using COMCMS.Web.ExceptionHandler; -using Lib.Core.MiddlewareExtension.Extension; -using Senparc.Weixin.Entities; -using Senparc.CO2NET; -using Senparc.CO2NET.RegisterServices; -using Senparc.Weixin; -using Senparc.CO2NET.Cache; -using System.Configuration; -using COMCMS.Web.Configuration; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Http.Features; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using Microsoft.Extensions.WebEncoders; +using Newtonsoft.Json.Serialization; +using Senparc.CO2NET; +using Senparc.CO2NET.Cache; +using Senparc.CO2NET.RegisterServices; +using Senparc.Weixin.Entities; using Senparc.Weixin.RegisterServices; -using Microsoft.AspNetCore.Routing.Constraints; namespace COMCMS.Web { @@ -75,13 +72,12 @@ namespace COMCMS.Web services.Configure(Configuration.GetSection("SystemSetting")); services - .AddMvc(options => + .AddControllersWithViews(options => { //记录错误 options.Filters.Add(); }) - .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) - .AddJsonOptions(JsonOptionsConfig.ConfigJsonOptions); + .AddNewtonsoftJson(options =>options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()); //防止汉字被自动编码 services.Configure(options => @@ -96,22 +92,27 @@ namespace COMCMS.Web services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); // 设置表单内容限制 - services.Configure(formOptions => - { - formOptions.ValueLengthLimit = int.MaxValue; // 表单内容大小限制,默认4194304,单位byte - formOptions.MultipartBodyLengthLimit = int.MaxValue; // 如果是multipart,默认134217728 - }); + //services.Configure(options => + //{ + // //formOptions.ValueLengthLimit = int.MaxValue; // 表单内容大小限制,默认4194304,单位byte + // //formOptions.MultipartBodyLengthLimit = int.MaxValue; // 如果是multipart,默认134217728 + // options.ValueCountLimit = int.MaxValue; + // options.ValueLengthLimit = int.MaxValue; + // options.KeyLengthLimit = int.MaxValue; + // options.MultipartBodyLengthLimit = int.MaxValue; + // options.MultipartBoundaryLengthLimit = int.MaxValue; + //}); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp, IOptions senparcSetting, IOptions senparcWeixinSetting) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider svp, IOptions senparcSetting, IOptions senparcWeixinSetting) { app.Use(async (context, next) => { context.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); await next(); }); - + if (env.IsDevelopment()) { @@ -134,25 +135,26 @@ namespace COMCMS.Web app.UseCookiePolicy(); app.UseAuthentication(); app.UseStaticHttpContext(); + app.UseRouting(); - app.UseMvc(routes => + app.UseEndpoints(endpoints => { - routes.MapRoute( + endpoints.MapControllerRoute( name: "areas", - template: "{area:exists}/{controller=Index}/{action=Index}/{id?}" + pattern: "{area:exists}/{controller=Index}/{action=Index}/{id?}" ); - routes.MapRoute( + endpoints.MapControllerRoute( name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); - routes.MapRoute( + pattern: "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapControllerRoute( name: "article", - template: "{title}/index.html", + pattern: "{title}/index.html", defaults: new { controller = "Home", action = "Article" } ); - routes.MapRoute( + endpoints.MapControllerRoute( name: "article2", - template: "{title}/", + pattern: "{title}/", defaults: new { controller = "Home", action = "Article" } ); }); diff --git a/README.md b/README.md index e3283fd..c25a38e 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,暂时不带前台 ### 技术简要 -- .net core 2.1.6 (请注意升级本地SDK 或者runtime) +- .net core 3.0 (请注意升级本地SDK 或者runtime) - 数据库:Mysql 5.7 /Mysql 8.0 - ORM:数据库操作使用XCode,目前支持mysql、sqlserver。详细见:https://github.com/NewLifeX/X -- 据库驱动使用:MySQL官方驱动,8.0.13 +- 据库驱动使用:MySQL官方驱动,8.0.19 - 后台模板是H+ - 编辑器采用CKeditor 支持截图粘贴进去,上传图片采用webuploader @@ -27,7 +27,7 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,暂时不带前台 - NewLife.UserGroup.WebUploader 大文件上传 -- WebTest 测试站点 +- WebTest 测试站点;暂时屏蔽 - data 目录是初始化sql ,目前是mysql diff --git a/XCoder/Entity/Build.tt b/XCoder/Entity/Build.tt index c5cba09..0ab4363 100644 --- a/XCoder/Entity/Build.tt +++ b/XCoder/Entity/Build.tt @@ -8,7 +8,8 @@ <# // 设置当前工作目录 PathHelper.BaseDirectory = Host.ResolvePath("."); - // 导入模型文件并生成实体类,模型文件、输出目录、命名空间、连接名 + // 导入模型文件并生成实体类,模型文件、输出目录、命名空间、连接名、中文文件名 + //EntityBuilder.Build(String xmlFile = null, String output = null, String nameSpace = null, String connName = null, Boolean? chineseFileName = true); EntityBuilder.Build(); //var tables = DAL.ImportFrom("Company.Project.xml"); diff --git a/XCoder/XCoder(代码生成器).csproj b/XCoder/XCoder(代码生成器).csproj index 17fce69..a88ca6f 100644 --- a/XCoder/XCoder(代码生成器).csproj +++ b/XCoder/XCoder(代码生成器).csproj @@ -30,8 +30,8 @@ 4 - - ..\packages\NewLife.Core.8.3.2019.822\lib\net45\NewLife.Core.dll + + ..\packages\NewLife.Core.8.3.2019.923\lib\net46\NewLife.Core.dll @@ -46,8 +46,8 @@ - - ..\packages\NewLife.XCode.9.14.2019.822\lib\net45\XCode.dll + + ..\packages\NewLife.XCode.9.14.2019.923\lib\net46\XCode.dll diff --git a/XCoder/packages.config b/XCoder/packages.config index fc025bc..fc3a7a1 100644 --- a/XCoder/packages.config +++ b/XCoder/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file