Open Closed

Overriding redirect for home page to login view #1211


User avatar
0
joe@tronactive.com created
  • ABP Framework version: v4.2.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

I want to redirect a user to the actual login page https://localhost:44343/Account/Login if they are not logged in. Not the home page. I tried adding an override HomeController but it doesn't seem to be overriding the frameworks. I put a break poing in the Index method and it never gets hit. Any ideas why?

[Dependency(ReplaceServices = true)] public class HomeController : AbpController { public ActionResult Index() { if (CurrentUser.IsAuthenticated) { return View(); }

        return Redirect("/Account/Login");
    }
}

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

    hi joe@tronactive.com

    I want to redirect a user to the actual login page https://localhost:44343/Account/Login if they are not logged in. Not the home page.

    How to reproduce this?

  • User Avatar
    0
    joe@tronactive.com created

    Instead of going to the Home page with the login button. I want it to go to the https://localhost:44343/Account/Login. As you can see the images below. I was able to do this in the Angular version with the API with a HomeController and the below code. But in the MVC app it doesn't work.

    public class HomeController : AbpController { public ActionResult Index() { if (CurrentUser.IsAuthenticated) { return View(); } return Redirect("/Account/Login"); } }

  • User Avatar
    0
    joe@tronactive.com created

    Nevermind, I was being stupid. I created a Home folder under Views/Home and then moved the index.html file from the Pages folder to that Views/Home folder and it worked as I wanted it to.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 18, 2024, 05:54