Is there an existing issue for this?
Describe the bug
In a Blazor Web App created with dotnet new blazor -int Auto -ai false, WebAssembly takeover fails for anonymous users when ASP.NET Core authorization uses a fallback policy that requires authenticated users.
The app explicitly marks both Razor components and static assets as anonymous:
app.MapStaticAssets().AllowAnonymous()
app.MapRazorComponents<App>(...).AllowAnonymous()
However, after navigating to an InteractiveAuto page and refreshing once WebAssembly should take over, the app fails because a framework asset under /_framework/ is returned as 401 Unauthorized.
In my repro, the failing asset is:
https://localhost:7112/_framework/resource-collection.9RAE4.js
The hash changes per build, but the behavior is consistent.
This leaves the page in the Blazor error state and prevents WebAssembly mode from loading for anonymous users.
If I sign in first, the same page refresh works and WebAssembly takes over correctly.
Expected Behavior
If both MapRazorComponents(...) and MapStaticAssets() are explicitly marked with AllowAnonymous(), InteractiveAuto should be able to load its required /_framework/* assets for anonymous users even when a fallback policy is configured.
Refreshing an InteractiveAuto page as an anonymous user should succeed and switch to WebAssembly mode instead of failing with a 401 on a framework asset.
Steps To Reproduce
Repro repo:
https://github.com/alexaka1/repro-dotnet--aspnetcore-65993
- Clone the repro repo.
- Run the server project over HTTPS so it listens on
https://localhost:7112.
- Open
https://localhost:7112.
- Navigate to
/counter.
- On first load, server interactivity works and the page shows
Counter (Server).
- Wait briefly so the WebAssembly assets can download.
- Refresh the page.
- The page fails and shows the Blazor error UI.
- Inspect the network/console output and observe that a hashed
/_framework/resource-collection.*.js request returns 401 Unauthorized.
- Navigate to
/auth and sign in.
- Navigate back to
/counter.
- Refresh the page again.
- Now the page loads successfully and shows
Counter (WebAssembly).
Important repro detail:
The app configures a fallback policy requiring authenticated users, while also explicitly calling:
app.MapStaticAssets().AllowAnonymous()
app.MapRazorComponents<App>(...).AllowAnonymous()
Exceptions (if any)
Browser console:
ManagedError: AggregateException_ctor_DefaultMessage (Failed to fetch dynamically imported module: https://localhost:7112/_framework/resource-collection.9RAE4.js
TypeError: Failed to fetch dynamically imported module: https://localhost:7112/_framework/resource-collection.9RAE4.js)
HTTP response for the failing asset:
HTTP/2 401
.NET Version
10.0.201
Anything else?
Relevant app configuration in the repro:
- Blazor Web App template
dotnet new blazor -int Auto -ai false
- static routing (
<Routes /> is not given a render mode directly)
- custom auth scheme based on a cookie
- authorization configured with both:
- default policy requiring authenticated users
- fallback policy requiring authenticated users
MapStaticAssets().AllowAnonymous()
MapRazorComponents<App>(...).AllowAnonymous()
Observed behavior:
- anonymous user: refresh on
/counter fails because /_framework/resource-collection.*.js returns 401
- signed-in user: refresh on
/counter succeeds and WebAssembly mode works
This seems related to fallback policy behavior around framework/static resources used by InteractiveAuto.
I am 100% sure this is related to #51836 and the implicit fix was not fully complete.
Is there an existing issue for this?
Describe the bug
In a Blazor Web App created with
dotnet new blazor -int Auto -ai false, WebAssembly takeover fails for anonymous users when ASP.NET Core authorization uses a fallback policy that requires authenticated users.The app explicitly marks both Razor components and static assets as anonymous:
app.MapStaticAssets().AllowAnonymous()app.MapRazorComponents<App>(...).AllowAnonymous()However, after navigating to an InteractiveAuto page and refreshing once WebAssembly should take over, the app fails because a framework asset under
/_framework/is returned as401 Unauthorized.In my repro, the failing asset is:
https://localhost:7112/_framework/resource-collection.9RAE4.jsThe hash changes per build, but the behavior is consistent.
This leaves the page in the Blazor error state and prevents WebAssembly mode from loading for anonymous users.
If I sign in first, the same page refresh works and WebAssembly takes over correctly.
Expected Behavior
If both
MapRazorComponents(...)andMapStaticAssets()are explicitly marked withAllowAnonymous(), InteractiveAuto should be able to load its required/_framework/*assets for anonymous users even when a fallback policy is configured.Refreshing an InteractiveAuto page as an anonymous user should succeed and switch to WebAssembly mode instead of failing with a 401 on a framework asset.
Steps To Reproduce
Repro repo:
https://github.com/alexaka1/repro-dotnet--aspnetcore-65993
https://localhost:7112.https://localhost:7112./counter.Counter (Server)./_framework/resource-collection.*.jsrequest returns401 Unauthorized./authand sign in./counter.Counter (WebAssembly).Important repro detail:
The app configures a fallback policy requiring authenticated users, while also explicitly calling:
app.MapStaticAssets().AllowAnonymous()app.MapRazorComponents<App>(...).AllowAnonymous()Exceptions (if any)
Browser console:
ManagedError: AggregateException_ctor_DefaultMessage (Failed to fetch dynamically imported module: https://localhost:7112/_framework/resource-collection.9RAE4.js
TypeError: Failed to fetch dynamically imported module: https://localhost:7112/_framework/resource-collection.9RAE4.js)
HTTP response for the failing asset:
HTTP/2 401
.NET Version
10.0.201
Anything else?
Relevant app configuration in the repro:
dotnet new blazor -int Auto -ai false<Routes />is not given a render mode directly)MapStaticAssets().AllowAnonymous()MapRazorComponents<App>(...).AllowAnonymous()Observed behavior:
/counterfails because/_framework/resource-collection.*.jsreturns 401/countersucceeds and WebAssembly mode worksThis seems related to fallback policy behavior around framework/static resources used by InteractiveAuto.
I am 100% sure this is related to #51836 and the implicit fix was not fully complete.