简体   繁体   中英

Azure AD Authentication: Redirect to originating page

I am working on an old ASP.NET Web forms application converting it from windows authentication to Azure AD authentication. I have completed the normal flow where when user opens the home page and is not authorized, user is redirected to Azure AD for login and from there to the configured redirect page.

Only scenario that I am finding it difficult to implement is when user clicks on the application link of specific page from bookmarks or emails, after authentication he is redirect to redirect URL only. I want user to be shown the exact page link he clicked on.

I understand that only single URL can be configured to be used as redirect URL and in that particular page I have to implement the logic to redirect user to the original page. But I am not able to find any way to recognize the originating page in the code.

My Authentication code is in Global.asax file as below

    void Application_AuthenticateRequest(object sender, EventArgs e)
    {
    if (!Request.IsAuthenticated && !Request.Path.ToLower().Contains("error"))
    {
    var properties = new AuthenticationProperties() { RedirectUri = "/"};
    
    HttpContext.Current.GetOwinContext().Authentication.Challenge(
    properties,
    OpenIdConnectAuthenticationDefaults.AuthenticationType);
    }
}

In Startup.cs I have mentioned the Azure AD SSO configuration

How do I get the originating page from where user was redirect to Azure AD authentication page?

You should use returnURL and other parameters in the session variables (Global.asax --> Session_start event) After successfuly authentication through Azure AD, it will be redirected to the redirect URL (default page - static). From their, you shoule be able to get returbURL and parameters from session. I tried this appraoch and it is working fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM