My Developer Friends
my Login table have 3 field username, userpass, userrole.
From Login Page I would like to store Session["Role"], once I capture Role (Admin/User) then I will populate Treeview based on the Role
so, pls help me how to capture Role thru session.
private bool ValidateLogin(string strUserName, string strPassword) { bool blnValidLogin = false; SqlDataReader sqlDr = null;
SqlConnection sqlConn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]); string strSQL = "Select username, userpass, userrole From login Where username = '" + strUserName + "' And userpass = '" + strPassword + "'";
try { sqlConn.Open(); SqlCommand sqlCmd = new SqlCommand(strSQL, sqlConn); sqlDr = sqlCmd.ExecuteReader(); if (sqlDr.HasRows) { blnValidLogin = true; Session["LoggedIn"] = "LoggedIn";
//string role = (string)sqlDr[2]; //Session["Role"] = "role"; } return blnValidLogin; } catch (SqlException ex) { ctrlLogin.FailureText = ex.Message; return false; } finally { sqlConn.Close(); } }
|
| Author: ANIL PANDEY 05 Sep 2008 | Member Level: Diamond | Rating: Points: 6 |
hi,
please refer the following code..
protected void btnLogin_Click(object sender, ImageClickEventArgs e) { string strLoginID = string.Empty; string strPassword = string.Empty; string strQuery; string strUname; string strPwd; SqlDataReader drd; SqlConnection con = new SqlConnection(strConStr); SqlCommand cmd = new SqlCommand();
strLoginID = txtLoginID.Text; strPassword = txtPassword.Text; strQuery = "Select Sno,UserName,Pwd from tbUsers where UserName='" + txtLoginID.Text.Trim() + "' and Ac_Status='E'"; con.Open(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = strQuery; drd = cmd.ExecuteReader(); if (drd.HasRows) { while( drd.Read()) { if ((drd["UserName"].ToString() == txtLoginID.Text.Trim()) && (drd["Pwd"].ToString() == txtPassword.Text.Trim())) { Session["UID"] = drd[0].ToString(); Session["UName"] = drd[1].ToString(); if(check status) { Session["UType"] = Convert.ToInt32("1"); //Admin Response.Redirect("adminhome.aspx"); } else { Session["UType"] = "2"; //User Response.Redirect("attsheet.aspx"); } } else { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = "Invalid login ID or password."; txtLoginID.Text = ""; txtPassword.Text = ""; txtLoginID.Focus(); } } } else { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = "User does not exist."; txtLoginID.Text = ""; txtPassword.Text = ""; txtLoginID.Focus(); } }
Regards Anil Pandey
Thanks & Regards Anil Kumar Pandey
|
| Author: samir dutta 05 Sep 2008 | Member Level: Gold | Rating: Points: 1 |
Thanx Anil for your reply. but it not solved my problem. I want to know how can i store UserRole into session variable from the following sql query
pls help
|