How do I redirect to a specific page after signing in to Azure AD?

I am using Azure AD login in my application. I want to redirect to specific actions after a successful azure ad login. My Startup.Auth.cs file has below code. But this is not a redirecturi redirect. Anyone can suggest me how to redirect to a custom page after successful login.

public static void ConfigureAuth(IAppBuilder app)
        {
            app.UseKentorOwinCookieSaver();
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri,
                    RedirectUri = redirectUri,
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        SecurityTokenValidated = context =>
                        {
                            context.Response.Redirect("/members/logon");
                            return Task.FromResult(0);
                        },
                        AuthenticationFailed = context =>
                        {
                            if (context.Exception.Message.StartsWith("OICE_20004") || context.Exception.Message.Contains("IDX10311"))
                            {
                                context.SkipToNextMiddleware();
                                context.Response.Redirect("/members/logon");
                                return Task.FromResult(0);
                            }

                            return Task.FromResult(0);
                        }
                    }
                });
        }

      

Thank,

+3


source to share


1 answer


how to redirect to custom page after successful login

In AccountController, try to change the callback redirect url:



    public void SignIn()
    {
        // Send an OpenID Connect sign-in request.
        if (!Request.IsAuthenticated)
        {
            HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/home/about" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
        }
    }

      

use / controllerName / actionName. Once OWIN has verified the token and retrieved the required data, the user will be redirected to the URL you specified.

+3


source







All Articles