From 2bce7290fef1f282eb9216682d2477ccd246b756 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Sat, 2 Jun 2018 09:50:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8D=87=E7=BA=A7=E5=88=B0.n?= =?UTF-8?q?et=20core=202.1?= 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 | 6 +- COMCMS.Common/CookiesHelper.cs | 4 ++ COMCMS.Common/MyHttpContext.cs | 56 +++++++++++++++---- COMCMS.Core/COMCMS.Core.csproj | 2 +- .../AdminCP/Controllers/LoginController.cs | 3 +- .../Areas/AdminCP/Views/Shared/TipPage.cshtml | 23 ++++++-- COMCMS.Web/COMCMS.Web.csproj | 18 +++--- COMCMS.Web/Controllers/HomeController.cs | 37 +++++++++++- COMCMS.Web/Startup.cs | 34 +++++++++-- COMCMS.Web/Views/Home/Contact.cshtml | 2 +- XCoder/XCoder(代码生成器).csproj | 4 +- 12 files changed, 151 insertions(+), 40 deletions(-) diff --git a/COMCMS.API/COMCMS.API.csproj b/COMCMS.API/COMCMS.API.csproj index b69fa4d..30903b4 100644 --- a/COMCMS.API/COMCMS.API.csproj +++ b/COMCMS.API/COMCMS.API.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 diff --git a/COMCMS.Common/COMCMS.Common.csproj b/COMCMS.Common/COMCMS.Common.csproj index 66ea28d..17e1db8 100644 --- a/COMCMS.Common/COMCMS.Common.csproj +++ b/COMCMS.Common/COMCMS.Common.csproj @@ -1,13 +1,13 @@ - netcoreapp2.0 + netcoreapp2.1 - + - + diff --git a/COMCMS.Common/CookiesHelper.cs b/COMCMS.Common/CookiesHelper.cs index 9b16881..07dbe96 100644 --- a/COMCMS.Common/CookiesHelper.cs +++ b/COMCMS.Common/CookiesHelper.cs @@ -11,6 +11,10 @@ namespace COMCMS.Common /// public class CookiesHelper { + public CookiesHelper() + { + } + #region 获取Cookies /// /// 读cookie值 diff --git a/COMCMS.Common/MyHttpContext.cs b/COMCMS.Common/MyHttpContext.cs index f051981..02b7032 100644 --- a/COMCMS.Common/MyHttpContext.cs +++ b/COMCMS.Common/MyHttpContext.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Text; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; namespace COMCMS.Common { @@ -10,19 +12,51 @@ namespace COMCMS.Common /// public static class MyHttpContext { - public static IServiceProvider ServiceProvider; - static MyHttpContext() - { } - - public static HttpContext Current + private static IHttpContextAccessor _accessor; + public static HttpContext Current => _accessor.HttpContext; + internal static void Configure(IHttpContextAccessor accessor) { - get - { - object factory = ServiceProvider.GetService(typeof(IHttpContextAccessor)); - HttpContext context = ((IHttpContextAccessor)factory).HttpContext; - return context; - } + + _accessor = accessor; + } + + //public static IServiceProvider ServiceProvider; + + //static MyHttpContext() + //{ } + + //public static HttpContext Current + //{ + // get + // { + + // object factory = ServiceProvider.GetService();// ServiceProvider.GetService(typeof(IHttpContextAccessor)); + // HttpContext context = ((IHttpContextAccessor)factory).HttpContext; + // return context; + // } + //} //需要在sartup中加入 } + + public static class StaticHttpContextExtensions + { + + public static void AddMyHttpContextAccessor(this IServiceCollection services) + { + + services.AddSingleton(); + } + + public static IApplicationBuilder UseStaticHttpContext(this IApplicationBuilder app) + { + + var httpContextAccessor = app.ApplicationServices.GetRequiredService(); + + MyHttpContext.Configure(httpContextAccessor); + + return app; + + } + } } diff --git a/COMCMS.Core/COMCMS.Core.csproj b/COMCMS.Core/COMCMS.Core.csproj index 64a8f85..4c50a07 100644 --- a/COMCMS.Core/COMCMS.Core.csproj +++ b/COMCMS.Core/COMCMS.Core.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs index 4246c55..91a09e2 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs @@ -29,6 +29,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #endregion #region 低版本IE界面 + //判断低版本IE public IActionResult Ie() { return View(); @@ -73,7 +74,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //验证用户 if (string.IsNullOrEmpty(username)) { - tip.Message = "请输入用户名!"; + tip.Message = "请输入用户名!"+ key; return Json(tip); } if (string.IsNullOrEmpty(password) || Utils.GetStringLength(password) < 5) diff --git a/COMCMS.Web/Areas/AdminCP/Views/Shared/TipPage.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Shared/TipPage.cshtml index fbb98bc..b06e0a0 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Shared/TipPage.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Shared/TipPage.cshtml @@ -40,11 +40,26 @@ - - @Html.Partial("_FooterJS") - + + + + + + + + + + + + + - + + + + + +