The app is using Azure AD B2C for authentication
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => {
Configuration.Bind("AzureAdB2C", options);
});
by default when a page has the [Authorize()] Attribute it redirects to the Azure AD B2C login page if user is not authenticated.
Instead I want the redirect to go back the application home page. What is the way to accomplish that?
EDIT Attribute created after answer provided. This solved my problem.
public class AuthorizeRedirectAttribute : Attribute, IAuthorizationFilter { public AuthorizeRedirectAttribute() { }
public void OnAuthorization(AuthorizationFilterContext filterContext)
{
if(!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
filterContext.Result = new RedirectToPageResult("Landing");
}
}
}