ok tengo hacer un login en visual studio usando las reglas de mi profesor
Archivo login

Código ASP:
Ver original
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
<style type="text/css">
.normal {
width: 250px;
border: 1px solid #000;
}
.normal th, .normal td {
border: 1px solid #000;
}
</style>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="normal" >
<th scope="col">Usuario</th>
<th>
<asp:TextBox ID="txtUsuario" runat="server"></asp:TextBox>
</th>
<tr></tr>
<th scope="col">Clave</th>
<th>
<asp:TextBox ID="txtClave" runat="server"></asp:TextBox>
</th>
</table>
<asp:Button ID="Button1" runat="server" Text="Entrar"
PostBackUrl="~/procesarLogin.aspx" />
</div>
</form>
</body>
</html>
Y aqui la madre del cordero:
La regla de mi profesor es enviar usando un "PostBackUrl" a un archivo para que otro aspx haga el login
Este el "Procesarlogin.aspx" es el que no se hacer , el codigo no se como arreglarlo.
Código vb:
Ver original
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class procesarLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String user = Request["txtUsuario"];
String clave = Request["txtClave"];
Conexion con = new Conexion();
con.conectar();
/// que debe hacer, tomar los label y si esta en la BD, dejar pasar
try
{
if (con.validar(user) > 0)
{
Response.Redirect("menu.aspx");
}
else
{
Response.Write("No se encontro usuario");
}
}
catch(SqlException ex)
{
Response.Write("No se puede ejecutar" + ex.Message);
}
con.desconectar();
}
}
La clase que hace todo por si acaso
Código ASP:
por su atencion gracias, ojala alguien pueda ayudarme Ver original
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/// <summary>
/// Summary description for Conexion
/// </summary>
public class Conexion
{
SqlConnection conn;
SqlCommand comando;
public Conexion()
{
conn = new SqlConnection("Data Source=VESTERGAARD-PC\\VESTERGAARD;Initial Catalog=crud;User ID=sa;Password=123456");
}
public String conectar()
{
try
{
conn.Open();
}
catch (SqlException e)
{
return "Error:" + e.Message;
}
return "Conexion exitosa";
}
public String desconectar()
{
try
{
conn.Close();
}
catch (SqlException e)
{
return "Error:" + e.Message;
}
return "Desconexion exitosa";
}
public int validar(String user, String clave)
{
comando = new SqlCommand("Select * from usuario where usuario='"+user+"'and clave='"+clave+"'");
return comando.ExecuteNonQuery();
}
}
 
 


