Base solution for your next web application

Activities of "arnoldkesselaar"

Hi Everyone,

I am utilising the "multi-tenant, multi-db" scenario.

Consider the following function.

#1 The line with UserManager.ConfirmEmailAsync will not work without the using statement above it. It can't find the correct tenanted user.

#2 The line with await UserManager.UpdateAsync(user) doesn't work without the UnitOfWorkManager.Current.SetTenantId using statement above it.

I would have thought that #2 being within the scope of #1 would be ok without the extra using statement. Why do I need to do this?

[AbpAllowAnonymous]
        [UnitOfWork]
        public async Task<SecureUserResultDto> ActivateUser(SecureUserDto userDto)
        {
            var activationResult = new SecureUserResultDto();

            var user = await GetTenantedUser(userDto.UserEmail);

            if (user != null)
            {
                using (AbpSession.Use(user.TenantId, user.Id))
                {
                    var result = await UserManager.ConfirmEmailAsync(user, userDto.SecurityToken);
                    if (result.Succeeded)
                    {
                        user.IsEmailConfirmed = true;
                        user.IsActive = true;
                        user.Password = HashUserPassword(user, userDto.Password);

                        try
                        {
                            using (UnitOfWorkManager.Current.SetTenantId(user.TenantId))
                                await UserManager.UpdateAsync(user);

                            activationResult.Success = true;
                            activationResult.UserEmail = user.EmailAddress;
                        }
                        catch (Exception e)
                        {
                            activationResult.Errors = new List<string>();
                            activationResult.Errors.Add(e.Message);
                        }

Sigh... I found a bug in my tenant mapping function and the wrong tenant was being selected there.

Thanks for the reply in any case :)

Hello, great system, thanks for building it!

As mentioned in the subject, we have setup a multi-tenant/multi-database scenario. I am also utilising the AngularJS front end to access the .NET CORE 1.1 API. I am using the "Abp.TenantId" to indicate to the back end api the tenant I wish to act in.

Here is my problem scenario: I have 2 "admin" users who can create other users. Each admin user belongs to a separate tenant. If I login as the admin user for t1 and create a user, that user has a tenant id of "1" (correct). Ok, now, I logout and then login to t2 (second tenant). I create a user for that tenant and the tenant id in the database is still "1"! The record is in the t2 database, which is even more strange....

Can anyone shed some light on this? If I shutdown the api and my browser, then login as t2 admin, the correct "TenantId" value is used.

Thanks for your help, Arnold.

Ok, I kinda figured it out...

I have initialised my tenant db with the user I need, when combined with DisableFilter(MayHaveTenant) and SetTenantId(TenantId) I can retrieve the user I want. I guess the users will need to have unique email addresses across tenants, so they can be identified. I will worry about this in the user creation process, so that I validate that the user isn't registered in another tenant (my business rules).

Is that the correct approach?

Are tenant users stored in the host database?

Showing 1 to 5 of 5 entries