Base solution for your next web application
Open Closed

Change website from single tenant single database to multitenant single database #12415


User avatar
0
mittera created

Hello,

I am trying to change a website from Single Tenant Single Database to MultiTenant Single Database.

I change the const to:
public const bool MultiTenancyEnabled = true;

I added TenantId to my entities and added the DbContext for each entity:
modelBuilder.Entity<InventoryAllocation>(i => { i.HasIndex(e => new { e.TenantId }); });
I ran the migration script and updated the database.

When I go into Swagger log in as Default tenant with my admin user, and I use CreateTenant, I get:
{ "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "Required permissions are not granted. At least one of these permissions must be granted: Creating new tenant", "details": null, "validationErrors": null }, "unAuthorizedRequest": true, "__abp": true }

When I edit my admin user in user management and click permissions I don't see CreateTenant as a permission.

How can I create a tenant?


5 Answer(s)
  • User Avatar
    0
    mittera created

    I just manually inserted a Tenant into the DB table directly.

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @mittera

    Did you configure the permissions before creating the tenant with the host user? In the AppAuthorizationProvider class, as shown in the screenshot below, are there permissions related to the tenant?

    image.png

  • User Avatar
    0
    mittera created

    Hi @mittera

    Did you configure the permissions before creating the tenant with the host user? In the AppAuthorizationProvider class, as shown in the screenshot below, are there permissions related to the tenant?

    image.png

    I am running on my localhost against our dev database. I can't seem to login as the host admin.
    admin@aspnetzero.com

    I get invalid username / password. I changed my account password then I copied the password hash from that to the host admin but still can't login.

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @mittera

    Can you verify the value assigned to the tenancyName parameter in the LoginAsync method of the LogInManager? For Angular projects, this is checked within the GetLoginResultAsync method inside TokenAuthController. For MVC projects, it is checked in the AccountController.

    When attempting to log in as a host user, the tenancyName value should be null.

  • User Avatar
    0
    mittera created

    Hi @mittera

    Can you verify the value assigned to the tenancyName parameter in the LoginAsync method of the LogInManager? For Angular projects, this is checked within the GetLoginResultAsync method inside TokenAuthController. For MVC projects, it is checked in the AccountController.

    When attempting to log in as a host user, the tenancyName value should be null.

    Thanks that was helpful. I was able to login and create a tenant. This can be closed.