ASP NET Core Authorized Page - Not redirecting to correct page

Omar 1 Reputation point
2021-11-06T21:50:36.3+00:00

I am trying to create a basic ASP NET core web page where one page requires authorization (a method of logging in via Microsoft identity or b2c). One is via a organization account and the other is via a partner account.

There are two sign in buttons in the navigation bar however if the user is not signed in and clicks on the "Protected" page they should be navigated to the "LoginMethod.cshtml" This LoginMethod page is already coded in the sense that it brings up a page with two buttons (ORG and Partner) and when clicked takes the user to the correct sign in page. Of course the current issue with this might be - if a user is not authorized and clicks on a Protected page and it redirects to LoginMethod - after logging in it wont redirect to the Protected page they wanted to access but just the home page

Currently:

I can click on the "Protected" page, it redirects me to the Azure AD login page, if i login in it will take me to the protected page HOWEVER I don't want it to go to the azure ad page i want it to go to the "LoginMethod" page which has 2 buttons to choose which login method to use... I am setting the application cookie property but perhaps i'm missing something key;

Protected.cshtml.cs page

[Authorize]
    public class ProtectedModel : PageModel
    {
        private readonly ILogger
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,461 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 26,201 Reputation points
    2021-11-07T12:50:47.983+00:00

    My best guess is you are trying to provide users multiple login providers. ASP.NET Core Identity provides this feature.

    Introduction to Identity on ASP.NET Core

    1 person found this answer helpful.