Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/04/2005, 07:55
Avatar de Nombela
Nombela
 
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
donde esta el fallo??

es para una autentificacion pero me redirecciona a la pagina del login:

private void submit_ServerClick(object sender, System.EventArgs e)
{
// Initialize FormsAuthentication, for what it's worth
FormsAuthentication.Initialize();

// Create our connection and command objects
string connectionString = ConfigurationSettings.AppSettings["conexion"];
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Usuarios WHERE UsLogin=@UsLogin " +
"AND UsPass=@UsPass";
// Fill our parameters
cmd.Parameters.Add("@UsLogin", SqlDbType.NVarChar, 50).Value = txtusuario.Value;
cmd.Parameters.Add("@UsPass", SqlDbType.NVarChar, 50).Value = txtpassword.Value;

// Execute the command
conn.Open();
//men.alert(cmd.CommandText);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
// Create a new ticket used for authentication
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
txtusuario.Value, // Username associated with ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie
reader.GetString(1), // User-data, in this case the roles
FormsAuthentication.FormsCookiePath);// Path cookie valid for

// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket

// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;

// Add the cookie to the list for outgoing response
if (cooky.Checked) Response.Cookies.Add(cookie);

// Redirect to requested URL, or homepage if no previous page
// requested
string returnUrl = "Default.aspx";
if (returnUrl == null) returnUrl = "/";

// Don't call FormsAuthentication.RedirectFromLoginPage since it
// could
// replace the authentication ticket (cookie) we just added
Response.Redirect(returnUrl);
}
else
{
int maxLoginAttempts = (int)Session["MaxLoginAttempts"];
if (Session["LoginCount"].Equals(maxLoginAttempts))
{
//mensaje.alert("Ha excedido el numero de intentos para acceder");
msg.Text="Ha excedido el numero de intentos para acceder";
msg.Visible=true;
}
else
{
//mensaje.alert("Error al intentar logarse");
msg.Text="Error al intentar logarse";
msg.Visible=true;
// Track the number of login attempts
int loginCount = (int)Session["LoginCount"];
loginCount += 1;
Session["LoginCount"] = loginCount;
}
}
reader.Close();
conn.Close();
}