[英]Get tenantId for mobile app (ASP.NET Boilerplate)
我使用 asp.net 樣板作為 Web 項目,以及移動應用程序的后端。
該應用程序是多租戶的。
我有一種驗證移動訪問代碼的方法。
這是代碼
[AllowAnonymous]
[ProducesResponseType(typeof(UserDataModel), 200)]
[ProducesResponseType(401)]
[HttpPost]
public async Task<IActionResult> ValidateMobileAccessCode(MobileInvitationCodeInput input)
{
var tenant = await _tenantRepository.GetAll().Where(x => x.Id == AbpSession.TenantId).FirstOrDefaultAsync();
var userId = await _userMobileAccessCodeService.ValidateCodeAndGetUserIdAsync(input.CodeValue);
if (userId == null)
{
return Unauthorized();
}
var user = await _userManager.GetUserOrNullAsync(new UserIdentifier(AbpSession.TenantId, userId.Value));
return Ok(new UserDataModel
{
UserId = userId.Value,
CodeValue = input.CodeValue,
Name = user.FullName,
EmailAddress = user.EmailAddress,
CompanyName = tenant == null ? "Host tenant" : tenant.TenancyName
});
}
但是這一行var tenant = await _tenantRepository.GetAll().Where(x => x.Id == AbpSession.TenantId).FirstOrDefaultAsync();
將返回 null,因為我在移動應用程序中沒有 session。
如何獲取移動應用程序的租戶 ID?
我試圖通過文檔找到解決方案,但沒有運氣
您可以通過 Header Abp.TenantId 設置 TenantId。 也有可能解決租戶拋出自定義租戶解析器機制。 您需要實現中間件,該中間件將在處理您的請求之前運行並將其添加到配置中。
Configuration.MultiTenancy.Resolvers.Add<DefaultTenantResolveContributor>();
您應該從接口繼承:
ITenantResolveContributor
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.