public class Cuenta
{
public string Nameu { get; set; }
public string passwordus { get; set; }
public string Cargo { get; set; }
}
public class CuentaController : Controller
{
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
SqlDataReader dr;
// GET: Cuenta
[HttpGet]
public ActionResult Login()
{
return View();
}
void connectionString()
{
con.ConnectionString = "data source=DESKTOP-6C8HTE4; database=Naturist3_0; integrated security=true;";
}
[HttpPost]
public ActionResult Verify(Cuenta acc)
{
connectionString();
con.Open();
com.Connection = con;
com.CommandText = "select username, password, rol from usuario where username='"+acc.Nameu+"', password='"+acc.passwordus+"' and rol='"+acc.Cargo+"'";
dr = com.ExecuteReader();
if(dr.Read())
{
con.Close();
return Redirect ("../sitioWeb/Inicio.aspx");
}
else
{
con.Close();
return View("error");
}
}
}
Respuesta
¿Demasiados anuncios?
aFrost
Puntos
275
Dentro del if dr.Read()
, mira a ver los datos del usuario que tiene el resultado y redirije a una u otra con otro if
, algo parecido a esto:
if(dr.Read())
{
con.Close();
data = dr[0]
Console.WriteLine(String.Format("{0}", data));
if (data.rol == "admin") { // O como sea que vengan tus datos
return Redirect ("../sitioWeb/Admin.aspx");
} else {
return Redirect ("../sitioWeb/Inicio.aspx");
}
}