简体   繁体   中英

Asp.net redirect to page based Azure AD user

Hello, I have asp.net web forms project with Azure AD authentication, now in this project i have two forms "webfrom1.aspx" and "webform2.aspx" now i need that, if user "it" is login then redirect to "web form 1.aspx" or if user "finance" login then redirect to "web form 2.aspx". please help me! Thanks

作为身份验证配置的一部分,您可以将RedirectUri指定到一个页面,该页面可以根据用户决定重定向的位置(webform1.aspx或webform2.aspx)。

if user "it" is login then redirect to "web form 1.aspx" or if user "finance" login then redirect to "web form 2.aspx".

You cannot redirect to different URLs from Azure AD based on user's information. Instead, you will have place the logic at landing page of your application such as Home page URL.

在此输入图像描述

Then you direct user to desired page based on your business logic. For example,

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (User != null && User.Identity.IsAuthenticated)
        {
            switch (User.Identity.Name.ToLower())
            {
                case "it":
                    Response.Redirect("~/WebForm1.aspx");
                    break;
                case "finance":
                    Response.Redirect("~/WebForm2.aspx");
                    break;
            }
        }
    }
}

Please feel free to take a look at my working sample code written in ASP.NET Core using Visual Studio 2017 at GitHub.

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