Open Closed

How to set the project to jump directly to the login page #1335


User avatar
0
zhonggj created
  • UI type: Blazor server
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:How to set the project to jump directly to the login page
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

12 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Have you tried using NavigationManager in Index page?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhonggj created

    Haven't tried, help provide a sample code.

    Like your example website, it automatically jumps to the login page.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can give it a try. I think it will be works.

    Like your example website, it automatically jumps to the login page.

    The demo website is angular. You are using Blazor Server.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhonggj created

    I am using blazor server, and I found that your example is not enough. The effect I want is that when accessing the system homepage, if there is no login, it will automatically jump to the login page. There is no need to manually click login and then jump to the login page.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can inject the ICurrentUser service and use IsAuthenticated to check the user whatever is logged.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    abpVAndy created

    hi

    You can give it a try. I think it will be works.

    Like your example website, it automatically jumps to the login page.

    The demo website is angular. You are using Blazor Server.

    Hi maliming,

    Where the code for Angular. I also need to do like jumping to the login page. We use angular and Identity Server Separated.

    Thx

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try this method in Angular.

    this.authService.navigateToLogin();
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    pvaz created

    Hi Maliming,

    it was good to have an example on how to do it using mvc, I have the same need and cannot find a proper example.

    Thx

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi pvaz

    You can call ChallengeAsync in yourOnGetAsync method of IndexModel for MVC tiered application.

    public class IndexModel : MyProjectNamePageModel
    {
        public async Task OnGetAsync()
        {
            if (!CurrentUser.IsAuthenticated)
            {
                await HttpContext.ChallengeAsync("oidc");
            }
        }
    
        public async Task OnPostLoginAsync()
        {
            await HttpContext.ChallengeAsync("oidc");
        }
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    pvaz created

    Hi Maliming,

    thank you for your quick reply.

    Perhaps my question I was not clear. When the user is not authenticated to redirect to /Account/Login.

    Using your example I get:

    "An unhandled exception occurred while processing the request. InvalidOperationException: No authentication handler is registered for the scheme 'oidc'. The registered schemes are: idsrv, idsrv.external, Abp.ConfirmUser, Identity.Application, Identity.External, Identity.TwoFactorRememberMe, Identity.TwoFactorUserId, Bearer, Google, Microsoft, Twitter. Did you forget to call AddAuthentication().AddSomeAuthHandler? Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties)"

    Thx

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi pvaz

    I think you can redirect user to any page.

    if (!CurrentUser.IsAuthenticated)
    {
        //redirect to /Account/Login
    }
    

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.redirect?view=aspnetcore-5.0

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    pvaz created

    Hi,

    solved this way using your advice:

    var redirectUrl = UriHelper.BuildAbsolute(HttpContext.Request.Scheme, HttpContext.Request.Host, "/Account/Login"); await HttpContext.ChallengeAsync(new AuthenticationProperties { RedirectUri = redirectUrl });

    return;`

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
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.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.