i write c# code to check if the user type = 1 depended on value comes from datareader
but i got this error Invalid attempt to read when no data is present
this is my code
Java
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
Code
string name = "";Code
if (Session["usernames"] != "" & Session["usernames"] != null)Code
{ name = Session["usernames"].ToString();Code
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["soom_dbConnectionString"].ConnectionString);Code
SqlCommand command = new SqlCommand("SELECT user_type FROM user_data where user_name='"+name+"'");Code
command.Connection = connection;Code
command.CommandType = CommandType.Text;Code
connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);Code
if (reader.HasRows) {Code
reader.Read();Code
if (reader["user_type"]== "1")Code
{ Response.Redirect("../admincp/Default.aspx");Code
} elseCode
{ Response.Redirect("../Access_Denied.aspx");Code
}Code
}Code
VB.NET
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 to
string name = "";Code
if (Session["usernames"] != "" & Session["usernames"] != null)Code
{ name = Session["usernames"].ToString();Code
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["soom_dbConnectionString"].ConnectionString);Code
SqlCommand command = new SqlCommand("SELECT user_type FROM user_data where user_name='"+name+"'");Code
command.Connection = connection;Code
command.CommandType = CommandType.Text;Code
connection.Open();Code
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);Code
if (reader.HasRows)Code
{ reader.Read(); string type = reader["user_type"].ToString();Code
if (type == "1")Code
{ Response.Redirect("../admincp/Default.aspx");Code
} elseCode
{ Response.Redirect("../Access_Denied.aspx");Code
}Code
}i enter infinite loop

waiting for the best answer
thanks in advance

VulpesRank #55 · 29.2K reputationPosted Aug 21, 2014, 4:11 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 22, 2014, 5:44 AM EDT
So basically we just checked if that was the case and only redirected to that page if it wasn't.
VulpesRank #55 · 29.2K reputationPosted Aug 21, 2014, 12:21 PM EDT
with this:
Abdullaziz Said said9 reputationPosted Aug 21, 2014, 2:18 PM EDT
This webpage has a redirect loop
Abdullaziz Said said9 reputationPosted Aug 22, 2014, 5:16 AM EDT
thanks in advance
Abdullaziz Said said9 reputationPosted Aug 22, 2014, 8:40 AM EDT
all pages
BTW this code in the admin masterpage :'(
VulpesRank #55 · 29.2K reputationPosted Aug 22, 2014, 3:14 PM EDT
Are you doing any authentication anywhere?
Abdullaziz Said said9 reputationPosted Aug 23, 2014, 11:10 AM EDT