Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsePathBase not working for Blazor Web App NET8 with individual accounts interactivity mode server #54723

Closed
1 task done
jsandv opened this issue Mar 23, 2024 · 4 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@jsandv
Copy link

jsandv commented Mar 23, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I created a new Blazor Web App with global server interactivity and individual accounts template in Visual Studio (17.9.4).

I need to run with PathBase middleware working.
i.e

var app = builder.Build();
**app.UsePathBase("/site2");**

Expected Behavior

I should now be able to use an url like:
https://localhost:5001/site2 as if im on https://localhost:5001
and
https://localhost:5001/site2/counter as if im on https://localhost:5001/counter

Steps To Reproduce

No response

Exceptions (if any)

if i navigate to https://localhost:5001/site2/counter in chrome/edge, it only displays "Not Found" message. If i refresh really fast i can see that the actual page is initially loaded, then im served with the "Not found" after. My guess is that when the socket attaches the blazor router does not find "/site2/counter" in this mode.

.NET Version

.NET SDK (8.0.203)

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 23, 2024
@mkArtakMSFT
Copy link
Member

Thanks for contacting us. It looks like you've missed to set the base tag with the same value. You can read more about this in our docs: https://learn.microsoft.com/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-8.0&tabs=visual-studio#app-base-path

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@mkArtakMSFT mkArtakMSFT added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Mar 27, 2024
@jsandv
Copy link
Author

jsandv commented Mar 28, 2024

Only setting app.UsePathBase("/alternate"); works in .NET6,7,8 for blazor server.

Anyways, i did test with setting base in app.razor as well.

Steps to repro:
1:
dotnet new blazor --all-interactive --auth Individual --interactivity Server --use-local-db
in program.cs on line 39, add
app.UsePathBase("/alternate"); //(directly after var app = builder.Build();)
Goto https://localhost:7277/alternate
You will get "Not found" in browser.

This workes in blazor server for .NET6,7,8

2:
Goto "app.razor"
Update line 7 to
<base href="/alternate/" />

3:
dotnet watch
The app will start and navigate to i.e http://localhost:5070/ in browser.
Side Note: The app will now fail. In blazor server 6,7,8, the app will work at both / and /alternate and /alternate/

In browser navigate to the actual "correct" destination based on the config, i.e: http://localhost:5070/alternate
The app will appear to work fine
Click on the page "Auth Required"
You will be redirected to login
Click on the page "Auth Required" once more
You will be redirected to: http://localhost:5070/alternate/auth
And you will get this exception in console:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.InvalidOperationException: Endpoint /auth (/auth) contains authorization metadata, but a middleware was not found that supports authorization.
      Configure your application startup by adding app.UseAuthorization() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAuthorization() must go between them.
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.ThrowMissingAuthMiddlewareException(Endpoint endpoint)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
         at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Builder.Extensions.UsePathBaseMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

In summary i am unable to run the app on a sub path using the provided template and documentation.

@Ronzan
Copy link

Ronzan commented Apr 30, 2024

Hey @jsandv - did you happen to find a solution to this?
I just added app.UsePathBase() to my Blazor 8 SSR/WASM project and when trying to redirect back to the login page to another page that requires auth, I get the same exception. This didn't happen before I added app.UsePathBase() and I have also set the <base href=""> in app.razor

@willpinha
Copy link

I'm having the same problem mentioned by @jsandv. Any updates on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

4 participants