BEST
DEALS
OF THE
YEAR!
SAVE UP TO $3,000
24 NOV
1 DEC
00 Days
00 Hrs
00 Min
00 Sec
Open Closed

Immediately direct unauthenticated users to login page #6987


User avatar
0
jhulbertpmn created
  • ABP Framework version: v8.0.4
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)

When an unauthenticated user navigates to my application, I would like to immediately direct them to the login page, as the full application requires a user to be authenticated (no functionality for a user not logged in). I was able to get part way there by adding [Authorize] to the ComponentBase for my Blazor application - it does direct the user to the login page if they aren't authenticated - but first it briefly displays the main page with the empty menu on the left and the login button on the right, then redirects to the login page, which isn't ideal. Is it possible to immediately direct the user to the login page without displaying the main layout first?


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    You can try to check and redirect to login page in the middleware

    ....
    app.UseAuthorization();
    
    app.Use(async (context, next) =>
    {
        if(context.User.Identity?.IsAuthenticated != true && !context.Request.Path.Value.StartsWith("/Account/Login"))  
        {
            context.Response.Redirect("/Account/Login");
            return;
        }
        await next();
    });
    
    app.UseSwagger();
    
    ....
    
  • User Avatar
    0
    jhulbertpmn created

    perfect!

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on November 20, 2025, 09:12
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.