You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scenario is to do with hosting two (multiple) different blazor wasm client applications, from a single .net core host project, and serving the correct one up on the root "/" url.
Prior to Blazor 3.2 preview 2, a single host could chose to serve up different front end client wasm projects on the root path, based on some logic like this:
In this scenario, there are two blazor client wasm projects, and the host can serve up the correct one based on a decision it makes such as who is the current tenant. This sets up a FileProvider pointing to the correct wasm's static content location. The client wasm projects can all have files named "image1.png" but there are no conflicts - no issues.
After the upgrade to blazor 3.2 preview 2 and the switch to using static assets - it looks like it will have to become something like this:
appBuilder.UseBlazorFrameworkFiles(); // blazor framework files can be served up from root url path
if(isTenantA)
{
// we want to serve up "ClientA" spa on the root path "/"
IFileProvider fp = GetStaticFileProviderFor<ClientA.Program>();
endpoints.MapFallbackToFile("index.html", new StaticFileOptions()
{
FileProvider = fp
});
}
else
{
// we want to serve up "ClientB" spa on the root path "/"
IFileProvider fp = GetStaticFileProviderFor<ClientB.Program>();
endpoints.MapFallbackToFile("index.html", new StaticFileOptions()
{
FileProvider = fp
});
}
Where GetStaticFileProviderFor<TProgramType>(); is a method I'll have to write myself that builds a FileProvider that only resolves the particular SPA's static content, but on the root "/" request path.
However the first issue is that the client SPA projects that are referenced from the host (via a project reference) now cause a build error as they each have a file with the same name in their wwwroot directories - so I now get this build error that I didn't see previoulsy:
Severity Code Description Project File Line Suppression State
Error Conflicting assets with the same path '/images/FOO_Black_Green_Logo_RGB.svg' for content root paths 'C:\Users\DarrellTunnell\source\repos\FOO\src\FOO.Landing.Page\wwwroot\images\FOO_Black_Green_Logo_RGB.svg' and 'C:\Users\DarrellTunnell\source\repos\FOO\src\FOO.Client\wwwroot\Images\FOO_Black_Green_Logo_RGB.svg'. FOO.Server C:\Program Files\dotnet\sdk\3.1.102\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets 191
After doing some more research, I found that I can potentially resolve this error by setting <StaticWebAssetBasePath> in each client SPA project to be something unique.
I still have to implement the aforementioned GetStaticFileProviderFor<TProgramType>(); method to set up an IFileProvider that will serve from the correct static assets location (ClientA vs ClientB) but serve that content up on the root path "/". I also need to make sure that I am serving the tenant up the SPA ClientA - then they should not be able to request files for /ClientB SPA. I know that Environment.WebRootFileProvider will be configured by default to be able to resolve both SPA's static assets on their Static Assets base paths: "/ClientA" and "/ClientB" respectively and I need to prevent that from happening.
I am pretty sure the key to this lies in building an IFileProvider to serve static assets based on the "StaticWebAssetBasePath" that I provide, but serve those files up on a different path i.e "/". In addition to this concern is working out how to replace or prevent the Environment.WebRootFileProvider from serving up Static Assets on their "StaticWebAssetBasePath"'s by default, so I can instead use the above IFileProvider via some additiopnal static files middleware to be explicit about the SPA i can serve up.
Any guidance on the resolution of this issue that did not exist in preview 1 would be greatly appreciated. Thanks
The text was updated successfully, but these errors were encountered:
This should result in the SPA static files being hidden by default, then I can add my own IFileProvider to the WebRootFileProvider that will serve up the correct SPA static files based on the tenant (I'll create a PhysicalFileProvider pointing to the "wwwroot/.clientA" and another for "wwwroot/.clientB" and wrap them in a custom IFileProvider that defers to the correct one of those depending on the current tenant.
This will work after a dotnet publish, but in development mode, i'll need #20605 to be fixed for the proper behaviour to work at development time too - i.e those static paths should not be served up by default.
I'll close this - setting <StaticWebAssetBasePath> in each project to a unique path resolves the immediate build issue with conflictint static asset paths. However that leads to #20605
Scenario is to do with hosting two (multiple) different blazor wasm client applications, from a single .net core host project, and serving the correct one up on the root "/" url.
Prior to Blazor 3.2 preview 2, a single host could chose to serve up different front end client wasm projects on the root path, based on some logic like this:
In this scenario, there are two blazor client wasm projects, and the host can serve up the correct one based on a decision it makes such as who is the current tenant. This sets up a FileProvider pointing to the correct wasm's static content location. The client wasm projects can all have files named "image1.png" but there are no conflicts - no issues.
After the upgrade to blazor 3.2 preview 2 and the switch to using static assets - it looks like it will have to become something like this:
Where
GetStaticFileProviderFor<TProgramType>();
is a method I'll have to write myself that builds a FileProvider that only resolves the particular SPA's static content, but on the root "/" request path.However the first issue is that the client SPA projects that are referenced from the host (via a project reference) now cause a build error as they each have a file with the same name in their wwwroot directories - so I now get this build error that I didn't see previoulsy:
After doing some more research, I found that I can potentially resolve this error by setting
<StaticWebAssetBasePath>
in each client SPA project to be something unique.However suppose I do set that for each wasm:
I still have to implement the aforementioned
GetStaticFileProviderFor<TProgramType>();
method to set up an IFileProvider that will serve from the correct static assets location (ClientA vs ClientB) but serve that content up on the root path "/". I also need to make sure that I am serving the tenant up the SPA ClientA - then they should not be able to request files for /ClientB SPA. I know thatEnvironment.WebRootFileProvider
will be configured by default to be able to resolve both SPA's static assets on their Static Assets base paths: "/ClientA" and "/ClientB" respectively and I need to prevent that from happening.I am pretty sure the key to this lies in building an IFileProvider to serve static assets based on the "StaticWebAssetBasePath" that I provide, but serve those files up on a different path i.e "/". In addition to this concern is working out how to replace or prevent the
Environment.WebRootFileProvider
from serving up Static Assets on their "StaticWebAssetBasePath"'s by default, so I can instead use the above IFileProvider via some additiopnal static files middleware to be explicit about the SPA i can serve up.Any guidance on the resolution of this issue that did not exist in preview 1 would be greatly appreciated. Thanks
The text was updated successfully, but these errors were encountered: