Ankush Roy
Ankush Roy

Reputation: 1631

How to implement Redirection to multiple folders using Forms Authentication

At present I am 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 wish to use Form Authentication method to implement this. Can Someone please provide me with Sample Code how to achieve this using Forms Authentication or tell me a procedure to implement this using Forms Authentication.

Thanks

Upvotes: 3

Views: 435

Answers (1)

Pankaj Mishra
Pankaj Mishra

Reputation: 20348

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");
    }

Upvotes: 2

Related Questions