Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Users role based Login in asp.net , c#

hey guys i have developed a website i have to users (Admin and users) also i have two database tables namely(tableUsers,tableAdmins) so what i want is that to check whether the currently logged in user is admin or student and redirect to thier own correspondent pages like (for admin admin/admin.aspx, for user home.aspx) thank u..

here is my code

string s = ConfigurationManager.ConnectionStrings["RegistrationConnectionString2"].ConnectionString;

protected void LoginButton_Click1(object sender, EventArgs e)
{

if (Page.IsValid)
{

using (SqlConnection con = new SqlConnection(s))
{
SqlCommand cmd = new SqlCommand("spUserlogin", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", TextBoxUsername.Text);
cmd.Parameters.AddWithValue("@password", TextBoxPassword.Text);
try
{
con.Open();
int value = (int)cmd.ExecuteScalar();
if (value == 1)
{

if (CheckBox1.Checked)
{
HttpCookie user = new HttpCookie("user_cookies"); 
user["New"] = TextBoxUsername.Text; // cookie content
user.Expires = DateTime.Now.AddYears(3); // give the time/duration of cookie
Response.Cookies.Add(user); // it gives the response in browser
}
else
{
Session["New"] = TextBoxUsername.Text;
}
Response.Redirect("home.aspx");
}
else
{
Label_Login.Visible = true;
Label_Login.Text = "Use Correct username and password";

}

}

catch (Exception ex)
{
 = true;
 = "Something went wrong! Contact your devloper " + ex.Message;
}
} 
}

}
}

Comments