项目升级到.net core 2.1
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user