将项目升级到.net core 3.0

This commit is contained in:
2019-10-30 17:14:02 +08:00
parent f6779f2339
commit d40f0b8eaf
19 changed files with 112 additions and 106 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
+5 -4
View File
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="NewLife.Core" Version="8.3.2019.822" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="NewLife.Core" Version="8.3.2019.923" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="PinYinConverterCore" Version="1.0.2" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0" />
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
</ItemGroup>
+2 -2
View File
@@ -22,11 +22,11 @@ namespace COMCMS.Common
/// <summary>
/// 程序绝对目录
/// </summary>
private static string _ContentRootPath = DI.ServiceProvider.GetService<IHostingEnvironment>().ContentRootPath;
private static string _ContentRootPath = DI.ServiceProvider.GetService<IWebHostEnvironment>().ContentRootPath;
/// <summary>
/// 静态文件
/// </summary>
private static string _WebRootPath = DI.ServiceProvider.GetService<IHostingEnvironment>().WebRootPath;
private static string _WebRootPath = DI.ServiceProvider.GetService<IWebHostEnvironment>().WebRootPath;
#region 方式
public enum CutMode
+2 -2
View File
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NewLife.XCode" Version="9.14.2019.822" />
<PackageReference Include="NewLife.XCode" Version="9.14.2019.923" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
+20 -20
View File
@@ -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
/// <returns>是否登录</returns>
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;//信息错误
}
}
@@ -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;
}
@@ -122,8 +122,8 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
/// <returns></returns>
public IActionResult Logout()
{
//Admin.ClearInfo();
Admin.ClearInfoAsync().Wait();
Admin.ClearInfo();
//Admin.ClearInfoAsync().Wait();
return Redirect("~/AdminCP/Login");
}
#endregion
@@ -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;
}
@@ -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<SystemSetting> attachsetting)
public UploadController(IWebHostEnvironment env, IOptions<SystemSetting> 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))
{
@@ -19,7 +19,7 @@
<select class="form-control m-b" name="KId" id="KId">
@foreach (var m in ViewBag.ListKinds)
{
<option value="@m.Id" @(ViewBag.lastkid == m.Id?"selected":"")>@m.KindName</option>
<option value="@m.Id">@m.KindName</option>
}
</select>
</div>
+12 -12
View File
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="2.3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="MimeKit" Version="2.3.1" />
<PackageReference Include="MySql.Data" Version="8.0.17" />
<PackageReference Include="NewLife.XCode" Version="9.14.2019.822" />
<PackageReference Include="MailKit" Version="2.3.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
<PackageReference Include="MimeKit" Version="2.3.2" />
<PackageReference Include="MySql.Data" Version="8.0.18" />
<PackageReference Include="NewLife.XCode" Version="9.14.2019.923" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Senparc.Weixin" Version="6.4.13" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.7.17" />
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.4.5" />
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.5.4" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="Senparc.Weixin" Version="6.6.102" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.9.102" />
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.5.102" />
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.7.102" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
</ItemGroup>
@@ -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;
}
@@ -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;
//日期类型默认格式化处理
+8 -5
View File
@@ -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<Startup>()
.Build();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
+38 -36
View File
@@ -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<SystemSetting>(Configuration.GetSection("SystemSetting"));
services
.AddMvc(options =>
.AddControllersWithViews(options =>
{
//记录错误
options.Filters.Add<HttpGlobalExceptionFilter>();
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(JsonOptionsConfig.ConfigJsonOptions);
.AddNewtonsoftJson(options =>options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
//防止汉字被自动编码
services.Configure<WebEncoderOptions>(options =>
@@ -96,22 +92,27 @@ namespace COMCMS.Web
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
// 设置表单内容限制
services.Configure<FormOptions>(formOptions =>
{
formOptions.ValueLengthLimit = int.MaxValue; // 表单内容大小限制,默认4194304,单位byte
formOptions.MultipartBodyLengthLimit = int.MaxValue; // 如果是multipart,默认134217728
});
//services.Configure<FormOptions>(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> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider svp, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> 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" }
);
});
+3 -3
View File
@@ -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
+2 -1
View File
@@ -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");
+4 -4
View File
@@ -30,8 +30,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NewLife.Core, Version=8.3.7173.39564, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NewLife.Core.8.3.2019.822\lib\net45\NewLife.Core.dll</HintPath>
<Reference Include="NewLife.Core, Version=8.3.7207.798, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NewLife.Core.8.3.2019.923\lib\net46\NewLife.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -46,8 +46,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="XCode, Version=9.14.7173.39578, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NewLife.XCode.9.14.2019.822\lib\net45\XCode.dll</HintPath>
<Reference Include="XCode, Version=9.14.7207.834, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NewLife.XCode.9.14.2019.923\lib\net46\XCode.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
+2 -2
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NewLife.Core" version="8.3.2019.822" targetFramework="net461" />
<package id="NewLife.XCode" version="9.14.2019.822" targetFramework="net461" />
<package id="NewLife.Core" version="8.3.2019.923" targetFramework="net461" />
<package id="NewLife.XCode" version="9.14.2019.923" targetFramework="net461" />
</packages>