问题描述
文档
我已阅读 https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy
处的文档我在应用程序项目中添加了一个自定义的 TenantResolveContributor,并将其添加到 WebModule.PreInitialize 中的集合中。
Configuration.MultiTenancy.Resolvers.Add<NameTenantResolveContributor>();
在 WebModule.Initialize 中,我解析了 TenantAppService,以便将其注入 RouteConfig。
TenantAppService tenantAppService = IocManager.Resolve<TenantAppService>();
RouteConfig.RegisterRoutes(RouteTable.Routes,tenantAppService);
当执行到达 RouteConfig 时,它正确进入 NameTenantResolveContributor,但 HttpContext 为空。
- Abp 包版本:6.0.0
- 基础框架:.Net
请求在此上下文中不可用
在 System.Web.HttpContext.get_Request()
在 DemoApp.MultiTenancy.NameTenantResolveContributor.ResolveTenantId() 在 >D:\src\ABP\DemoProject\6.0.0\src\DemoProject.Application\MultiTenancy\NameTenantResolveContributor.cs:line 40
在 Abp.MultiTenancy.TenantResolver.GetTenantIdFromContributors()
堆栈跟踪异常简短且不具描述性。当我复制详细信息时,消息是
System.Web.HttpException
HResult=0x80004005
Message=Request is not available in this context
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
using Abp.Configuration.Startup;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.MultiTenancy;
using Abp.Text;
using Abp.Web.MultiTenancy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace DemoApp.MultiTenancy
{
public class NameTenantResolveContributor : ITenantResolveContributor,ITransientDependency
{
private readonly IMultiTenancyConfig _multiTenancyConfig;
private readonly ITenantStore _tenantStore;
public NameTenantResolveContributor(IMultiTenancyConfig multiTenancyConfig,ITenantStore tenantStore)
{
_multiTenancyConfig = multiTenancyConfig;
_tenantStore = tenantStore;
}
public int? ResolveTenantId()
{
string tenancyName = "";
string[] urlParts = null;
var httpContext = HttpContext.Current;
if (httpContext == null)
{
return null;
}
//This is where the error occurs
urlParts = httpContext.Request.Url.Segments.Select(x => x.TrimEnd('/')).Skip(1).ToArray();
tenancyName = urlParts[0].ToLower();
var tenantInfo = _tenantStore.Find(tenancyName);
if (tenantInfo == null)
{
return null;
}
return tenantInfo.Id;
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)