You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
}
}
}