简体   繁体   中英

Get tenantId for mobile app (ASP.NET Boilerplate)

I using asp.net boilerplate as Web- project, and back-end for mobile apps.

The app is multitenancy.

I have a method to Validate mobile access code.

Here is it code

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

But this row var tenant = await _tenantRepository.GetAll().Where(x => x.Id == AbpSession.TenantId).FirstOrDefaultAsync(); will return null, as I not have session in mobile app.

How I can get tenant id for the mobile app?

I tried to find solution over docs, but no luck

You can set up TenantId by Header Abp.TenantId. There is also possibility to resolve tenant throw a Custom Tenant Resolver Mechanism. You need to implement middleware which will be run before your request will be process and add this to configuration.

Configuration.MultiTenancy.Resolvers.Add<DefaultTenantResolveContributor>();

You should inheritate from interface:

ITenantResolveContributor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM