Need help in page authentication
<p>I have set my login page with three roles,admin,employee,user.When i am log in as admin its redirecting to Admin/Default.aspx, when login as employee its redirecting to Employee/Default.aspx and when login as User its redirecting to User/Default.aspx, i mean all the functionality of these 3 roles are working fien. And suppose i have created new user say Sumit for him i have not given any role,in this case it shoud have been redirected to Default.aspx page rather its redirecting to User/Default.aspx page. Could somebody help me pls what is the reason??? Here is my entire code:</p>

<p>Login.aspx.cs:</p>

<pre><code> protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        Session["UserName"] = Login1.UserName;
        Session["Password"] = Login1.Password;
        string username = Login1.UserName.Trim();
        string password = Login1.Password.Trim();
        LoginBusinessLayer LB = new LoginBusinessLayer();      
        try
        {          
            if (LB.GetLogin(username,password) == true)
            {
                 if (Session["RoleName"].Equals("admin"))
                 {
                     FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
                     Response.Redirect("Admin/Default.aspx");
                 }
                 else if (Session["RoleName"].Equals("employee"))
                 {
                     FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
                     Response.Redirect("Employee/Default.aspx");
                 }
                 else if (Session["RoleName"].Equals("user"))
                 {
                     FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
                     Response.Redirect("User/Default.aspx");
                 }
                 else
                 {
                     Response.Redirect("Default.aspx");//Control is not coming in this else part
                 }
            }
        }
        catch(SqlException ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            LB = null;
        }
    }
</code></pre>

<p>BusinessLayer.cs:</p>

<pre><code>public class LoginBusinessLayer
{
        public bool GetLogin(string userid, string userrole)
        {
            LoginDataLayer LD = new LoginDataLayer();
            LD.GetUser(userid,userrole);
            return true;
        }
}
</code></pre>

<p>DataLayer.cs:</p>

<pre><code>public class LoginDataLayer
{
        SqlConnection con;
        SqlCommand com;
        SqlDataReader dr;
        string check;    
        public bool GetUser(string userid, string rolename)
        {
            if (HttpContext.Current.Session["UserName"] != null)
            {
                con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                con.Open();
                check = "Select ur.UserId,ur.UserName,rl.RoleName from aspnet_Users as ur,aspnet_Roles rl,aspnet_UsersInRoles as ir where ur.UserName = '"+HttpContext.Current.Session["UserName"] + "' and ur.UserId=ir.UserId and ir.RoleId=rl.RoleId";
                com = new SqlCommand(check, con);
                dr = com.ExecuteReader(CommandBehavior.CloseConnection);
                while (dr.Read())
                {
                    if (dr.HasRows)
                    {
                        HttpContext.Current.Session["UserId"] = dr["UserId"].ToString();
                        HttpContext.Current.Session["RoleName"] = dr["RoleName"].ToString();
                        return true;
                    }
                }
                con.Close();          
            }
            return false;
          }
}
</code></pre>

<p>Above red highligted code is not working.Your reply is highly appreciated.
Thanks,
Sumit</p>
