项目升级到.net core 2.1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" />
|
||||
<PackageReference Include="NewLife.Core" Version="7.0.6701.38514" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.1" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
|
||||
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace COMCMS.Common
|
||||
/// </summary>
|
||||
public class CookiesHelper
|
||||
{
|
||||
public CookiesHelper()
|
||||
{
|
||||
}
|
||||
|
||||
#region 获取Cookies
|
||||
/// <summary>
|
||||
/// 读cookie值
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
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<IHttpContextAccessor>();// 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<IHttpContextAccessor, HttpContextAccessor>();
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseStaticHttpContext(this IApplicationBuilder app)
|
||||
{
|
||||
|
||||
var httpContextAccessor = app.ApplicationServices.GetRequiredService<IHttpContextAccessor>();
|
||||
|
||||
MyHttpContext.Configure(httpContextAccessor);
|
||||
|
||||
return app;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -40,11 +40,26 @@
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@Html.Partial("_FooterJS")
|
||||
<!-- 自定义js -->
|
||||
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
||||
<script src="~/js/validation/jquery.validate.js"></script>
|
||||
<script src="~/js/validation/messages_zh.js"></script>
|
||||
<script src="~/js/layer/layer.js"></script>
|
||||
<script src="~/js/jquery.form.js"></script>
|
||||
<script src="~/js/rtpost.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
|
||||
<script src="~/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
|
||||
<!-- Bootstrap table -->
|
||||
<script src="~/js/treegrid/jquery.treegrid.min.js"></script>
|
||||
<script src="~/js/treegrid/jquery.treegrid.bootstrap3.js"></script>
|
||||
<script src="~/hplus/js/content.js?v=1.0.0"></script>
|
||||
|
||||
<script src="~/hplus/js/common.js"></script>
|
||||
<script src="~/hplus/js/plugins/iCheck/icheck.min.js"></script>
|
||||
<script src="~/js/webuploader/webuploader.min.js"></script>
|
||||
<script src="~/js/uploader.js"></script>
|
||||
<script src="~/editor/ckeditor/ckeditor.js"></script>
|
||||
<script src="~/js/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>
|
||||
<script>
|
||||
var index = parent.layer.getFrameIndex(window.name);
|
||||
function closethisdialog() {
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
|
||||
<PackageReference Include="MySqlConnector" Version="0.40.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
|
||||
<PackageReference Include="MySqlConnector" Version="0.40.4" />
|
||||
<PackageReference Include="NewLife.XCode" Version="9.7.6703.38907" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="14.12.3" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="1.9.1" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="14.14.0" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="1.10.5" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.5.0" />
|
||||
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Text;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace COMCMS.Web.Controllers
|
||||
{
|
||||
@@ -23,9 +24,18 @@ namespace COMCMS.Web.Controllers
|
||||
Configuration = new ConfigurationBuilder()
|
||||
.Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
|
||||
.Build();
|
||||
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
CookieOptions op = new CookieOptions
|
||||
{
|
||||
Expires = DateTime.Now.AddMinutes(10),
|
||||
Path = "/",
|
||||
HttpOnly = true
|
||||
};
|
||||
Response.Cookies.Append("abc", "123456", op);//用户名
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
@@ -35,17 +45,20 @@ namespace COMCMS.Web.Controllers
|
||||
CookiesHelper.WriteCookie("abc", Utils.GetRandomChar(20), 10);
|
||||
//sessiong
|
||||
SessionHelper.WriteSession("bcd", Utils.GetRandomChar(20));
|
||||
HttpContext.Session.SetString("abc", "123456");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Contact()
|
||||
{
|
||||
|
||||
ViewData["Message"] = "Your contact page.";
|
||||
string prekey = Utils.PrefixKey;
|
||||
Article a = Article.FindById(1);
|
||||
ViewBag.siteName = a.Title;
|
||||
|
||||
ViewBag.c = CookiesHelper.GetCookie("abc");
|
||||
string abc = HttpContext.Session.GetString("abc");
|
||||
ViewBag.c = CookiesHelper.GetCookie("abc")+ abc;
|
||||
ViewBag.d = prekey;
|
||||
return View();
|
||||
}
|
||||
@@ -102,5 +115,25 @@ namespace COMCMS.Web.Controllers
|
||||
return Content(s);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
const string SessionKeyName = "_Name";
|
||||
const string SessionKeyYearsMember = "_YearsMember";
|
||||
const string SessionKeyDate = "_Date";
|
||||
|
||||
public IActionResult Index3()
|
||||
{
|
||||
// Requires using Microsoft.AspNetCore.Http;
|
||||
HttpContext.Session.SetString(SessionKeyName, "Rick");
|
||||
HttpContext.Session.SetInt32(SessionKeyYearsMember, 3);
|
||||
return RedirectToAction("SessionNameYears");
|
||||
}
|
||||
public IActionResult SessionNameYears()
|
||||
{
|
||||
var name = HttpContext.Session.GetString(SessionKeyName);
|
||||
var yearsMember = HttpContext.Session.GetInt32(SessionKeyYearsMember);
|
||||
|
||||
return Content($"Name: \"{name}\", Membership years: \"{yearsMember}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-5
@@ -11,6 +11,7 @@ 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;
|
||||
@@ -31,13 +32,29 @@ namespace COMCMS.Web
|
||||
{
|
||||
//注入自己的HttpContext
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddMvc().AddSessionStateTempDataProvider();
|
||||
//services.AddMvc().AddSessionStateTempDataProvider();
|
||||
|
||||
services.Configure<CookiePolicyOptions>(options =>
|
||||
{
|
||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||
//options.CheckConsentNeeded = context => true;
|
||||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||
});
|
||||
|
||||
services.AddMyHttpContextAccessor();
|
||||
|
||||
services.AddDistributedMemoryCache();
|
||||
//添加Session 服务
|
||||
services.AddSession();
|
||||
services.AddSession(options =>
|
||||
{
|
||||
options.IdleTimeout = TimeSpan.FromSeconds(120);
|
||||
options.Cookie.HttpOnly = true;
|
||||
|
||||
});
|
||||
//部分系统配置
|
||||
services.Configure<SystemSetting>(Configuration.GetSection("SystemSetting"));
|
||||
|
||||
services.AddMvc();
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); ;
|
||||
//防止汉字被自动编码
|
||||
services.Configure<WebEncoderOptions>(options =>
|
||||
{
|
||||
@@ -61,18 +78,25 @@ namespace COMCMS.Web
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseBrowserLink();
|
||||
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
|
||||
//其他错误页面处理
|
||||
app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
|
||||
//启用Session
|
||||
app.UseSession();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseCookiePolicy();
|
||||
app.UseStaticHttpContext();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
@@ -95,7 +119,7 @@ namespace COMCMS.Web
|
||||
});
|
||||
|
||||
//加入HttpContext
|
||||
MyHttpContext.ServiceProvider = svp;
|
||||
//MyHttpContext.ServiceProvider = svp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
<h3>@ViewData["Message"]</h3>
|
||||
<h2>@ViewBag.siteName</h2>
|
||||
<h2>@ViewBag.c</h2>
|
||||
<h2 style="color:#ff0000">@ViewBag.c</h2>
|
||||
<h2>@ViewBag.d.ToString()</h2>
|
||||
|
||||
<address>
|
||||
|
||||
@@ -57,7 +57,9 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="data.project.xml" />
|
||||
<Content Include="data.project.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="生成实体类.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>生成实体类.log</LastGenOutput>
|
||||
|
||||
Reference in New Issue
Block a user