How to implement redirection to multiple folders using forms authentication

I am currently using this method to redirect to different folders.

private void btnLogin_Click(object sender, System.EventArgs e)
{
    string Role=string.Empty;
    if (!string.IsNullOrEmpty(Role = ValidateUser(txtUsername.Text, txtPassword.Text)))
    {
        If(Role=="Admin")
        {
             Response.Redirect("Admin/Default.aspx");
        }
        else if(Role=="Category_A_User")
        {
             Response.Redirect("Category_A_User/Default.aspx");
        }
        else if(Role=="Category_B_User")
        {
             Response.Redirect("Category_B_User/Default.aspx");
        }
        else if(Role=="Category_C_User")
        {
             Response.Redirect("Category_C_User/Default.aspx");
        }
        else if(Role=="Category_D_User")
        {
             Response.Redirect("Category_D_User/Default.aspx");
        }
    }
}

I can use sessions, but I want to use the form authentication method to implement it. Can someone please provide me a code example on how to achieve this using forms authentication or tell me the procedure to implement using forms authentication.

thank

+3
source share
1 answer
If(Role=="Admin")
    {
         FormsAuthentication.SetAuthCookie("UserName", true);
         Response.Redirect("Admin/Default.aspx");
    }
    else if(Role=="Category_A_User")
    {
         FormsAuthentication.SetAuthCookie("UserName", true);
         Response.Redirect("Category_A_User/Default.aspx");
    }
+2
source

Source: https://habr.com/ru/post/1795686/


All Articles