Asp.net 6 ASP.Net 6 Identity Calling Login at Startup Not Home Page

Richard Williams 15 Reputation points
2024-12-10T09:46:59.1266667+00:00

I wanted to quickly set up a new website, used one that I had built last year which uses full MS Identity management. This works fine but rather than calling Home/Index on startup it goes directly through to Login.cshtml. I cannot see any differences with the one that I designed before which opens with Index and then allows login when needed. Any ideas what could be routing the new website this way - the routing is the same: UseMVC endpoint shows "{area:exists}/{controller=Home}/{action=Index}/{id?}".

What could cause Login.cshtml and not Index.cshtml to open on startup?

Developer technologies | ASP.NET | ASP.NET Core
Microsoft Security | Microsoft Identity Manager
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-12-10T11:35:17.6266667+00:00

    Hi Richard, your concern about What could cause Login.cshtml and not Index.cshtml to open on startup is related to how you set up your authentication mechanism.

    Normally speaking, when we are working on MVC app, the home page url shall be /Home/Index just like what you shared in your question, and if the Index action method or the HomeController class has [Authorize] attribute on it, your app will redirect to the Login page when an unauthenticated request is trying to hit /Home/Index endpoint. And we can also use custom middleware or filter to achieve the redirection.

    But we didn't see any codes related to how you configure your authentication scheme. Could you please share more about your app if you didn't see any [Authorize] attribute or suspicious middleware in your app?

    One more thing, I always recognize Microsoft Identity as Microsoft Entra ID(known as Azure AD before) but it doesn't require to have a Login.cshtml within the App, I'm afraid what you had in your app shall be asp.net core Identity. Am I right?

    1 person found this answer helpful.
    0 comments No comments

  2. Richard Williams 15 Reputation points
    2024-12-10T16:57:36.6966667+00:00

    Problem solved. Thanks for reminding me about [Authorize] . I've used it many times to ensure that only legitimate users can access certain areas of the website. I discovered that the new basic MVC build had appended [Authorize] to the home controller, and, as there was no initial authorisation required, it was blocking access until the user was logged on. Very basic mistake on my part.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.