Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/04/2005, 01:46
Avatar de Nombela
Nombela
 
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 1 mes
Puntos: 1
cookieless="true"

Buenas, tengo un problema con las cookies, y es ke cuando el navegador no las acepta se me queda pillado y no me pasa a la pagina del defaul.aspx
LE he puesto cookieless=true para ke no me coja la validacion de cookies pero da hace lo mismo, porque pues ser???

Aqui va el codigo:

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=@username " +
"AND UsPass=@password";
// Fill our parameters
cmd.Parameters.Add("@username", SqlDbType.NVarChar, 50).Value = txtusuario.Value;
cmd.Parameters.Add("@password", SqlDbType.NVarChar, 50).Value = txtpassword.Value;
Response.Write(cmd.CommandText);
// Execute the command
conn.Open();
//men.alert(cmd.CommandText);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
Session["usuario"]=txtusuario.Value;
// 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
mensaje.alert(returnUrl);
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();