protected void Page_Load(object sender, EventArgs e) { string name = ""; if (Session["usernames"] != "" & Session["usernames"] != null) { name = Session["usernames"].ToString(); SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["soom_dbConnectionString"].ConnectionString); SqlCommand command = new SqlCommand("SELECT user_type FROM dbo.user_data where user_name='" + name + "'"); command.Connection = connection; command.CommandType = CommandType.Text; connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) { if (reader["user_type"] == "1") { Response.Redirect("../admincp/Default.aspx"); } else { Response.Redirect("../Access_Denied.aspx"); } } } }
and use this code also
string name = "";
if (Session["usernames"] != "" & Session["usernames"] != null)
{ name = Session["usernames"].ToString();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["soom_dbConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand("SELECT user_type FROM user_data where user_name='"+name+"'");
command.Connection = connection;
command.CommandType = CommandType.Text;
connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows) {
reader.Read();
if (reader["user_type"]== "1")
{ Response.Redirect("../admincp/Default.aspx");
} else
{ Response.Redirect("../Access_Denied.aspx");
}
when i use this code and iam sure that the user_type value is 1 it's redirect me to access_denied.aspx idk Whyand when i change the code tostring name = ""; if (Session["usernames"] != "" & Session["usernames"] != null) { name = Session["usernames"].ToString(); SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["soom_dbConnectionString"].ConnectionString); SqlCommand command = new SqlCommand("SELECT user_type FROM user_data where user_name='"+name+"'"); command.Connection = connection; command.CommandType = CommandType.Text; connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); if (reader.HasRows) { reader.Read(); string type = reader["user_type"].ToString(); if (type == "1") { Response.Redirect("../admincp/Default.aspx"); } else { Response.Redirect("../Access_Denied.aspx"); } } i enter infinite loop waiting for the best answerthanks in advance
connection.Open();
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows)
{ reader.Read(); string type = reader["user_type"].ToString();
if (type == "1")