Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have a Blazor Web application with 1 aspnetcore host and two blazor (webassembly) clients, all on .net9.0. I did not want to deal with hosting them on separate paths (through things like <base href=xx/>
as it involved an existing application which would have been difficult to migrate, so they are exposed on separate domains.
To separate their assets I have been using "StaticWebAssetBasePath" in the csproj's to g et two folders in the wwwroot (say app-1 and app-2). So for the sake of discussion, i have app.com which gets (largely) served from wwwroot/app-1 and my.app.com which gets (largely) served from wwwroot/app-2. They are both able to use the same api which is accessible by route /api/xxx.
Some issues I had with this are that the server had to be modified slightly to point the applications to the correct paths for certain requests (mostly different PathBase)
- the
_content
directory is published in the wwwroot instead of wwwroot/app-1, requests to assets here seem to work with the PathBase changes on the server. - resourcecollection.{fingerprint}.js and blazor.web.js do not exist on disk but generated by some middleware, it wont be served correctly unless the request pipeline has the correct PathBase set (app-1/app-2).
- _framework/dotnet.js will not be found with these PathBase changes on the server. I have to manually prepend the PathBase again to find the file like
/app-1/app-1/_framework/dotnet.js
.
So at this point I hack in a little middleware that essentially checks for any path some.file
if {pathbase}/some.file
exists on disk. Note that this does mean we are already looking for app-1/_framework/dotnet.js
so we add the "missing" segment.
Now here we are, up and running. A bit wacky that is has to be like this but sure. However, I noticed that fingerprinting is now suffering from the same weird double PathBase requirement issue:
- Like with _framework/dotnet.js, I am already effectively serving
/app-1/app-1/main.js
. Even though the browser thinks its serving/main.js
. To reiterate, I have to .UsePathBase in program.cs AND the middleware that adds the pathbase again, to the actual request path. - The fingerprinded asset paths (resolved in App.razor through the ComponentBase.Assets property) do not work either unless the path base is included in the path
/app-1/main.js
.
In the last point, I would be adding the pathbase THREE times. Amazingly, this would in turn break the resolution of _framework.dotnet.js and my middleware hack (which I am not keen on keeping) cannot work around this by checking for a file on disk, because only the StaticAssetsEndpointDataSource which knows which file the path may map to.
So I have gotten a bit stuck here.
Expected Behavior
- Static asset requests involving assets in a StaticAssetsBasePath directory need not add multiple PathBase's in the request uri to be resolved, wether they are fingerprinted or not.
- Fingerprinting url resolution considers the StaticAssetsBasePath
Steps To Reproduce
Sample blazor web repo + add an extra client.
Serve each client from a separate 'sub application' using MapWhen(ctx => domain == x, app => configureApp(app)
. and configure each app with a separate PathBase and UseEndpoints with MapStaticAssets and MapRazorComponents/MapRazorPages.
Then set the StaticAssetsBasePath in each blazor client's csproj file, matching the respective pathbases ofcourse.
Exceptions (if any)
No response
.NET Version
9.0.203
Anything else?
No response