Multi-Tenant Blazor Server Side app Hosted in Azure

Tom McCartan 25 Reputation points
2024-04-29T13:06:10.9633333+00:00

I am working on a new project to host a Multi-Tenant Application using the following technologies: Blazor Server Side, Hosted on an Azure App Service, Using Azure SignalR, using Feature Toggles in Azure App Configuration and Secured with Azure Active Directory and the Gateway will use Azure Front Door.

I have Azure Front Door configured with multiple DNS Entries with rules setup to evaluate the Route and inject a custom Header in the Request Object with the Customers Unique ID.

I need to be able to retrieve the Header and then dynamically set the Theme, Logo, Connection String, etc. for this customer within the Blazor Server Side Application.

I have tried Finbuckle. That worked initially, but does NOT work using Azure SignalR. I need to use Azure SignalR, because that is the only way Web Sockets are supported using Azure Front Door. And the only recommendation is to use HttpContextAccessor, which is not reliable.

I don't know how to read the Request in the Program.cs and store it to use in the MainLayout.razor OnInitializedAsync to set the theme prior to Render. I don't know if Middleware will work, as that will be outside the scope of the WebSocket request due to using Azure SignalR.

I am trying to read it in the App.razor.cs as there it appears you can read the HttpContext, but I don't know where to store it, as ProtectedSessionStorage is not available at that time.

So the question is, what is the recommendation to create a Multi-Tenant App, on blazor Server hosted in Microsoft Azure. It seems there should be a solution to this, as its all put together in the Microsoft ecosystem.

Any ideas, concepts, etc. would be appreciated.

Thanks,

Tom

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,577 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,758 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 65,131 Reputation points
    2024-04-29T16:01:52.24+00:00

    Blazor pre-render can access HttpContext safely via cascading state.

    [CascadingParameter]
    public HttpContext? HttpContext { get; set; }
    

    Then it can use persist render state to pass to the live blazor app.

    https://video2.skills-academy.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/persist-component-state?view=aspnetcore-8.0

    your other option would be in the server authentication code add the tenant id as a custom claim. I'd choose this option.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.