I have a legacy asp.net web forms application built in .net framework 4.8 Recently it is being upgraded to use Azure AD Open Id authentication. I used Microsoft Owin Project Git project as reference to configure the authentication. Authentication is working fine. I am able to retrieve user claims as well. However, in my project there is no login page. If user tries to access any page & he is not authenticated then it should direct to the IdP authority url for login. In a sample project below code is used to redirect user to IdP login page.
if (!Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
This is what I tried:
<authentication mode="None"></authentication>
<authorization>
<deny users="?" />
</authorization>
In global.asax
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (!Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
But user is not redirected to IdP login. What should I change here to implement this?