Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Tenant Id Session is null in Web.Core project #6616


User avatar
0
razkhan78 created

We have enable multi-tenancy in our application. In our application we need to display logo(custom logo uploaded by Tenant) on header as well as on some other pages. We have checked that there is one method "GetLogo()" in TenantCustomizationController. This controller exists in Web.Core project.

In "GetLogo()" method, tenantId is retrieved from AbpSession.GetTenantId(). And this tenantId will be passed to database for getting Image bytes from AbpBinaryObjects table. But in our system, we are getting AbpSession.GetTenantId()= null so logo (uploaded by Tenant) is not being displayed.

We are calling HeaderViewModel method "GetLogoUrl" which calls "GetLogo" from TenantCustomizationController. We are getting all values in LoginInformations.Tenant but not in TenantCustomizationController.

Please let us know how should we resolve this.


5 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    HeaderViewModel method "GetLogoUrl" which calls "GetLogo" from TenantCustomizationController

    It doesn't.

    Please let us know how should we resolve this.

    How to reproduce?

  • User Avatar
    0
    razkhan78 created

    1)LoadStop.Web.MVC\Areas\App\Views\Shared\Components\AppDefaultBrand\Default.chtml

    We have one "AppLogo" img tag with following src attribute on above page: src="@headerViewModel.GetLogoUrl(ApplicationPath, UiThemeCustomizer.IsTopMenuUsed || UiThemeCustomizer.IsTabMenuUsed ? UiThemeCustomizer.HeaderSkin: UiThemeCustomizer.LeftAsideAsideSkin)"

    2)LoadStop.Web.MVC\Areas\App\Models\Layout\HeaderViewModel.cs

    public string GetLogoUrl(string appPath, string menuSkin) { if (LoginInformations?.Tenant?.LogoId == null) { return appPath + $"Common/Images/app-logo-on-{menuSkin}.png"; }

    //id parameter is used to prevent caching only.
    return appPath + "TenantCustomization/GetLogo?id=" + LoginInformations.Tenant.LogoId;
    

    }

    3)LoadStop.Web.Core\Controllers\TenantCustomizationController.cs

    [AllowAnonymous] public async Task<ActionResult> GetLogo() {

    try
    {
    	var tenant = await _tenantManager.GetByIdAsync(AbpSession.GetTenantId());
    	if (!tenant.HasLogo())
    	{
    		return StatusCode((int)HttpStatusCode.NotFound);
    	}
    
    	var logoObject = await _binaryObjectManager.GetOrNullAsync(tenant.LogoId.Value);
    	if (logoObject == null)
    	{
    		return StatusCode((int)HttpStatusCode.NotFound);
    	}
    
    	return File(logoObject.Bytes, tenant.LogoFileType);
    }
    catch (System.Exception ex)
    {
    	Logger.Error("Catch-Exception in GetLogo: " + ex.Message);
    	throw;
    }
    

    }

    ==========================================================================================

    For our system, 3rd method "GetLogo" gets called and but AbpSession.GetTenantId()=null so it throws catch exception as per below: https://forum.aspnetboilerplate.com/viewtopic.php?p=21747

    Above issue is same as my issue.

    You can reproduce this issue on any of multi-tenancy enabled asp.net zero demo project where you can upload custom logo by tenant login and see that logo is being displayed on top left corner of header or not.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I couldn't reproduce this on our demo (http://volosoft.demo.aspnetzero.com). Are you able to reproduce it on our live demo ?

    Thanks,

  • User Avatar
    0
    razkhan78 created

    For reproducing that issue we need to enable multitenancy. Could you please create one Tenant for this demo so we can test on that Tenant.

    Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @razkhan78

    This is the login for the tenant named "Volosoft". So, you are seeing the tenant side of the app. When you go to settings page, you can see that you are able to select a logo.