mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-07 18:04:45 +08:00
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace Infrastructure
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
@@ -12,7 +14,6 @@
|
||||
Version = "";
|
||||
UploadPath = "";
|
||||
IdentityServerUrl = "";
|
||||
DbType = Define.DBTYPE_SQLSERVER;
|
||||
}
|
||||
/// <summary>
|
||||
/// SSO地址
|
||||
@@ -28,7 +29,7 @@
|
||||
/// <summary>
|
||||
/// 数据库类型 SqlServer、MySql
|
||||
/// </summary>
|
||||
public string DbType { get; set; }
|
||||
public Dictionary<string, string> DbTypes { get; set; }
|
||||
|
||||
/// <summary> 附件上传路径</summary>
|
||||
public string UploadPath { get; set; }
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Infrastructure.Extensions.AutofacManager;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Infrastructure.Utilities
|
||||
{
|
||||
public static class HttpContext
|
||||
{
|
||||
private static IHttpContextAccessor _accessor=AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||
|
||||
public static Microsoft.AspNetCore.Http.HttpContext Current => _accessor.HttpContext;
|
||||
|
||||
}
|
||||
}
|
||||
40
Infrastructure/Utilities/HttpContextUtil.cs
Normal file
40
Infrastructure/Utilities/HttpContextUtil.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Infrastructure.Extensions.AutofacManager;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Infrastructure.Utilities
|
||||
{
|
||||
public static class HttpContextUtil
|
||||
{
|
||||
private static IHttpContextAccessor _accessor=AutofacContainerModule.GetService<IHttpContextAccessor>();
|
||||
|
||||
public static Microsoft.AspNetCore.Http.HttpContext Current => _accessor.HttpContext;
|
||||
|
||||
/// <summary>
|
||||
/// 获取租户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetTenantId(this IHttpContextAccessor accessor)
|
||||
{
|
||||
string tenantId = "OpenAuthDBContext";
|
||||
|
||||
if (accessor != null && accessor.HttpContext != null)
|
||||
{
|
||||
//读取多租户ID
|
||||
var httpTenantId = accessor.HttpContext.Request.Query[Define.TENANT_ID];
|
||||
if (string.IsNullOrEmpty(httpTenantId))
|
||||
{
|
||||
httpTenantId = accessor.HttpContext.Request.Headers[Define.TENANT_ID];
|
||||
}
|
||||
|
||||
//如果没有租户id,或租户用的是默认的OpenAuthDBContext,则不做任何调整
|
||||
if (!string.IsNullOrEmpty(httpTenantId))
|
||||
{
|
||||
tenantId = httpTenantId;
|
||||
}
|
||||
}
|
||||
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user