Answered by:
removing cookies

Question
-
User1256512446 posted
Hi all:
I have
Partial Class codigo Inherits System.Web.UI.MasterPage Sub comprobar_cuenta(ByVal s As Object, ByVal e As AuthenticateEventArgs) Handles lgsesion.Authenticate Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString) Dim sqlc As New SqlCommand("seleccionar_datos_cuenta", cnconexion) sqlc.CommandType = CommandType.StoredProcedure sqlc.Parameters.AddWithValue("@vercuenta", True) sqlc.Parameters.AddWithValue("@seudonimo", lgsesion.UserName) sqlc.Parameters.AddWithValue("@contrasena", lgsesion.Password) cnconexion.Open() If sqlc.ExecuteScalar > 0 Then Request.Cookies("cuenta").Value = sqlc.ExecuteScalar If DirectCast(lgsesion.FindControl("rememberme"), CheckBox).Checked Then Request.Cookies("cuenta").Expires = DateTime.Now.AddYears(50) Else Request.Cookies("cuenta").Expires = DateTime.Now.AddMinutes(20) End If e.Authenticated = True Else If lgsesion.FailureText = "" Then lgsesion.FailureText = GetGlobalResourceObject("rmaestro", "cuentainexistente") e.Authenticated = False End If End Sub Sub comprobar_expresionesregulares(ByVal s As Object, ByVal e As LoginCancelEventArgs) Handles lgsesion.LoggingIn Dim strusuario As String, strcontrasena As String strusuario = lgsesion.UserName strcontrasena = lgsesion.Password lgsesion.FailureText = "" If InStr(strusuario, "'") > 0 OrElse InStr(strusuario, "<") > 0 OrElse InStr(strusuario, ">") > 0 Then lgsesion.FailureText = GetGlobalResourceObject("rgeneral", "seudonimoinvalido") End If If InStr(strcontrasena, "'") > 0 OrElse InStr(strcontrasena, "<") > 0 OrElse InStr(strcontrasena, ">") > 0 Then lgsesion.FailureText &= " " & GetGlobalResourceObject("rgeneral", "contrasenainvalida") End If End Sub Sub mostrar_saludo() Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString) Dim sqlc As New SqlCommand("seleccionar_datos_cuenta", cnconexion) sqlc.CommandType = CommandType.StoredProcedure sqlc.Parameters.AddWithValue("@vernombre", True) sqlc.Parameters.AddWithValue("@c10", Request.Cookies("cuenta").Value) pnlsesion.Visible = True lgsesion.Visible = False cnconexion.Open() DirectCast(lblsaludo, Label).Text = "<b>¡" & GetGlobalResourceObject("rgeneral", "hola") & " " & sqlc.ExecuteScalar & "!</b>" cnconexion.Close() End Sub Sub page_load(ByVal s As Object, ByVal e As EventArgs) Handles Me.Load Dim stronload As String = Nothing, inti As Integer Dim strtitulo As String = Page.Title ver_idiomas() If Not IsPostBack Then Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString) Dim sqlc As New SqlCommand("seleccionar_varios", cnconexion) Dim li As ListItem sqlc.CommandType = CommandType.StoredProcedure sqlc.Parameters.AddWithValue("@v0", 1) cnconexion.Open() Me.lblactualizado.Text = GetGlobalResourceObject("rmaestro", "actualizado") & " " & sqlc.ExecuteScalar cnconexion.Close() Me.lblcopyright.Text = "@ copyright " & Year(Now) hlnk1.Text = GetGlobalResourceObject("rgeneral", "titulo1") hlnk1.ToolTip = GetGlobalResourceObject("rgeneral", "clave1") hlnk1.NavigateUrl = "portada.aspx?idioma=" & Request.QueryString("idioma") & IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) > 0, "&ddlopciones=1", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar") & " " & LCase(GetGlobalResourceObject("rgeneral", "paginapersonal"))) > 0, "&ddlopciones=2", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) > 0 AndAlso Request.Cookies("cuenta") IsNot Nothing, "&ddlopciones=3", IIf(Request.QueryString("ddlopciones") IsNot Nothing, "&ddlopciones=" & Request.QueryString("ddlopciones"), "")))) hlnk2.Text = GetGlobalResourceObject("rgeneral", "titulo2") hlnk2.ToolTip = GetGlobalResourceObject("rgeneral", "clave2") hlnk2.NavigateUrl = "personal.aspx?idioma=" & Request.QueryString("idioma") & IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) > 0, "&ddlopciones=1", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar") & " " & LCase(GetGlobalResourceObject("rgeneral", "paginapersonal"))) > 0, "&ddlopciones=2", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) > 0 AndAlso Request.Cookies("cuenta") IsNot Nothing, "&ddlopciones=3", IIf(Request.QueryString("ddlopciones") IsNot Nothing, "&ddlopciones=" & Request.QueryString("ddlopciones"), "")))) For inti = 3 To 18 DirectCast(FindControl("hlnk" & inti), HyperLink).NavigateUrl = "obras.aspx?obra=" & inti - 2 & "&idioma=" & Request.QueryString("idioma") & IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) > 0, "&ddlopciones=1", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar") & " " & LCase(GetGlobalResourceObject("rgeneral", "paginapersonal"))) > 0, "&ddlopciones=2", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) > 0 AndAlso Request.Cookies("cuenta") IsNot Nothing, "&ddlopciones=3", IIf(Request.QueryString("ddlopciones") IsNot Nothing, "&ddlopciones=" & Request.QueryString("ddlopciones"), "")))) DirectCast(FindControl("hlnk" & inti), HyperLink).Text = GetGlobalResourceObject("rgeneral", "titulo" & inti) DirectCast(FindControl("hlnk" & inti), HyperLink).ToolTip = GetGlobalResourceObject("rgeneral", "clave" & inti) Next hlnk19.Text = GetGlobalResourceObject("rgeneral", "titulo19") hlnk19.ToolTip = GetGlobalResourceObject("rgeneral", "clave19") hlnkcresolia.ToolTip = GetGlobalResourceObject("rmaestro", "principal") hlnkcresolined.ToolTip = GetGlobalResourceObject("rmaestro", "colaboraciones") hlnkcresolined.NavigateUrl = "cresolined/default.aspxidioma=" & Request.QueryString("idioma") hlnkcresoliaza.ToolTip = GetGlobalResourceObject("rmaestro", "publicidad") hlnkcresoliaza.NavigateUrl = "cresoliaza/default.aspx?idioma=" & Request.QueryString("idioma") hlnk19.NavigateUrl = "premios.aspx?idioma=" & Request.QueryString("idioma") & IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) > 0, "&ddlopciones=1", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar") & " " & LCase(GetGlobalResourceObject("rgeneral", "paginapersonal"))) > 0, "&ddlopciones=2", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) > 0 AndAlso Request.Cookies("cuenta") IsNot Nothing, "&ddlopciones=3", IIf(Request.QueryString("ddlopciones") IsNot Nothing, "&ddlopciones=" & Request.QueryString("ddlopciones"), "")))) hlnk20.Text = GetGlobalResourceObject("rgeneral", "titulo20") hlnk20.ToolTip = GetGlobalResourceObject("rgeneral", "clave20") hlnk20.NavigateUrl = "visitas.aspx?idioma=" & Request.QueryString("idioma") & IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) > 0, "&ddlopciones=1", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar") & " " & LCase(GetGlobalResourceObject("rgeneral", "paginapersonal"))) > 0, "&ddlopciones=2", IIf(InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) > 0 AndAlso Request.Cookies("cuenta") IsNot Nothing, "&ddlopciones=3", IIf(Request.QueryString("ddlopciones") IsNot Nothing, "&ddlopciones=" & Request.QueryString("ddlopciones"), "")))) lgsesion.UserNameLabelText = GetGlobalResourceObject("rgeneral", "seudonimo") lgsesion.PasswordLabelText = GetGlobalResourceObject("rgeneral", "contrasena") lgsesion.RememberMeText = GetGlobalResourceObject("rgeneral", "recuerdame") li = New ListItem(LCase(GetGlobalResourceObject("rgeneral", "datospersonales")), 1) ddlopciones.Items.Add(li) li = New ListItem(LCase(GetGlobalResourceObject("rgeneral", "mipaginapersonal")), 2) ddlopciones.Items.Add(li) li = New ListItem(LCase(GetGlobalResourceObject("rgeneral", "misobras")), 3) ddlopciones.Items.Add(li) If Request.Form("ctl00$ddlopciones") IsNot Nothing Then ddlopciones.SelectedValue = Request.Form("ctl00$ddlopciones") ElseIf Request.QueryString("ddlopciones") IsNot Nothing Then ddlopciones.SelectedValue = Request.QueryString("ddlopciones") End If lgsesion.UserNameRequiredErrorMessage = GetGlobalResourceObject("rgeneral", "seudonimoobligatorio") lgsesion.PasswordRequiredErrorMessage = GetGlobalResourceObject("rgeneral", "contrasenaobligatoria") aseudonimocontrasenasolvidados.Title = GetGlobalResourceObject("rmaestro", "olvidos") aseudonimocontrasenasolvidados.Attributes.Add(" onclick", "window.open('seudonimocontrasenaolvidados.aspx?idioma=" & Request.QueryString("idioma") & "','ventana7','width=550,height=250')") aseudonimocontrasenasolvidados.InnerHtml = GetGlobalResourceObject("rgeneral", "seudonimocontrasenaolvidados") alistascorreo.Title = GetGlobalResourceObject("rmaestro", "estaraldia") alistascorreo.Attributes.Add(" onclick", "window.open('listascorreo.aspx?idioma=" & Request.QueryString("idioma") & "','ventana8','width=700,height=250,resizable=1,scrollbars=1')") alistascorreo.InnerHtml = GetGlobalResourceObject("rlistascorreo", "listascorreo") acontactar.Title = GetGlobalResourceObject("rmaestro", "contactemos") acontactar.Attributes.Add(" onclick", "window.open('contactar.aspx?idioma=" & Request.QueryString("idioma") & "','ventana9','width=550,height=250')") acontactar.InnerHtml = GetGlobalResourceObject("rgeneral", "contactar") aayuda.Title = GetGlobalResourceObject("rmaestro", "sabermas") aayuda.Attributes.Add(" onclick", "window.open('ayuda.aspx?idioma=" & Request.QueryString("idioma") & "','ventana10','width=700,height=500,resizable=1,scrollbars=1')") aayuda.InnerHtml = GetGlobalResourceObject("rgeneral", "ayuda") acontratos.Title = GetGlobalResourceObject("rmaestro", "especifiquemos") acontratos.Attributes.Add(" onclick", "window.open('contratos.aspx?idioma=" & Request.QueryString("idioma") & "','ventana11','width=700,height=500,resizable=1,scrollbars=1')") acontratos.InnerHtml = GetGlobalResourceObject("rmaestro", "contratos") aprivacidad.Title = GetGlobalResourceObject("rmaestro", "todoseguro") aprivacidad.Attributes.Add(" onclick", "window.open('privacidad.aspx?idioma=" & Request.QueryString("idioma") & "','ventana12','width=700,height=500,resizable=1')") aprivacidad.InnerHtml = GetGlobalResourceObject("rmaestro", "privacidad") If Request.QueryString("imprimir") IsNot Nothing Then tbmaestro.Visible = False If InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) = 0 AndAlso (InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) = 0 OrElse Request.QueryString("obra") IsNot Nothing) Then stronload &= "iniciar('')" Else stronload &= Choose(ddlopciones.SelectedValue, "iniciar('facturas,ingresos,invitaciones,obras,pagos,pedidos,puntosganados,puntosusados,seguimientos,solicitudes');", "iniciar('tcuentas,acuentas,mcuentas,dcuentas');", "", "", "iniciar('tcuentas,acuentas,mcuentas');") End If lgsesion.LoginButtonText = GetGlobalResourceObject("rgeneral", "iniciarsesion") btncerrarsesion.Text = GetGlobalResourceObject("rgeneral", "acabarsesion") btncerrarsesion.OnClientClick = "portada.aspx?idioma=" & Request.QueryString("idioma") btnir.Text = GetGlobalResourceObject("rmaestro", "ir") If Request.Cookies("cuenta") IsNot Nothing Then mostrar_saludo() Response.Write("cookie0=") Response.Write(Request.Cookies("cuenta").Value) 'Response.End() End If Else If InStr(strtitulo, GetGlobalResourceObject("rgeneral", "datospersonales")) = 0 AndAlso (InStr(strtitulo, GetGlobalResourceObject("rgeneral", "publicar")) = 0 OrElse Request.QueryString("obra") IsNot Nothing) Then stronload &= "cambio_campo('" & Request.Form("ctl00$cphcontenido$ddlcampos") & "','','" & Request.Form("ctl00$cphcontenido$ddloperandos") & "')" Else stronload &= Choose(ddlopciones.SelectedValue, "cambio_campo('" & Request.Form("ctl00$cphcontenido$ddlcamposfacturas") & "," & Request.Form("ctl00$cphcontenido$ddlcamposingresos") & "," & Request.Form("ctl00$cphcontenido$ddlcamposinvitaciones") & "," & Request.Form("ctl00$cphcontenido$ddlcamposobras") & "," & Request.Form("ctl00$cphcontenido$ddlcampospagos") & "," & Request.Form("ctl00$cphcontenido$ddlcampospedidos") & "," & Request.Form("ctl00$cphcontenido$ddlcampospuntosganados") & "," & Request.Form("ctl00$cphcontenido$ddlcampospuntosusados") & "," & Request.Form("ctl00$cphcontenido$ddlcamposseguimientos") & "," & Request.Form("ctl00$cphcontenido$ddlcampossolicitudes") & "','facturas,ingresos,invitaciones,obras,pagos,pedidos,puntosganados,puntosusados,seguimientos,solicitudes','" & Request.Form("ctl00$cphcontenido$ddloperandosfacturas") & "," & Request.Form("ctl00$cphcontenido$ddloperandosingresos") & "," & Request.Form("ctl00$cphcontenido$ddloperandosinvitaciones") & "," & Request.Form("ctl00$cphcontenido$ddloperandosobras") & "," & Request.Form("ctl00$cphcontenido$ddloperandospagos") & "," & Request.Form("ctl00$cphcontenido$ddloperandospedidos") & "," & Request.Form("ctl00$cphcontenido$ddloperandospuntosganados") & "," & Request.Form("ctl00$cphcontenido$ddloperandospuntosusados") & "," & Request.Form("ctl00$cphcontenido$ddloperandosseguimientos") & "," & Request.Form("ctl00$cphcontenido$ddloperandossolicitudes") & "');", "", "") End If End If End Sub Sub seleccionar_opcion(ByVal s As Object, ByVal e As EventArgs) Handles ddlopciones.SelectedIndexChanged Select Case s.SelectedValue Case 1 Server.Transfer("datospersonales.aspx?idioma=" & Request.QueryString("idioma")) Case 2 Server.Transfer("publicarpaginaspersonales.aspx?idioma=" & Request.QueryString("idioma")) Case 3 Server.Transfer("publicarobras.aspx?idioma=" & Request.QueryString("idioma")) End Select End Sub Sub transferir(ByVal s As Object, ByVal e As EventArgs) Handles btncerrarsesion.Click, btnir.Click If s.ID = "btncerrarsesion" Then Dim inti As Integer, strpaginas As String = Nothing pnlsesion.Visible = False Request.Cookies.Remove("cuenta") For inti = 1 To 20 If InStr(Page.Title, GetGlobalResourceObject("rgeneral", "titulo" & inti)) > 0 Then If inti > 2 AndAlso inti < 19 Then strpaginas = "obras.aspx?obra=" & inti - 2 & "&idioma=" & Request.QueryString("idioma") Else strpaginas = IIf(inti = 1, "portada", IIf(inti = 2, "personal", IIf(inti = 19, "premios", "visitas"))) & ".aspx?idioma=" & Request.QueryString("idioma") End If Exit For End If Next If strpaginas Is Nothing Then strpaginas = "portada.aspx?idioma=" & Request.QueryString("idioma") Server.Transfer(strpaginas) Else Select Case Request.Form("ctl00$ddlopciones") Case 1 Server.Transfer("datospersonales.aspx?idioma=" & Request.QueryString("idioma")) Case 2 Server.Transfer("publicarpaginaspersonales.aspx?idioma=" & Request.QueryString("idioma")) Case 3 Server.Transfer("publicarobras.aspx?idioma=" & Request.QueryString("idioma")) End Select End If End Sub Sub ver_idiomas() Dim intidioma As Integer = Request.QueryString("idioma") If intidioma = 1 Then Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("es") Thread.CurrentThread.CurrentUICulture = New CultureInfo("es") ElseIf intidioma = 2 Then Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en") Thread.CurrentThread.CurrentUICulture = New CultureInfo("en") ElseIf intidioma = 3 Then Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr") Thread.CurrentThread.CurrentUICulture = New CultureInfo("fr") Else Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("pt") Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt") End If End Sub End Class
In transferir I remove the cookie. If I ask for it after the removal, I get an error. So it is ok, it is removed
But in comprobar_cuenta, where I authenticate, if I ask for the cookie before the test, the cookie is there. What happens?
Thanks in advanced
Tuesday, February 3, 2015 10:57 AM
Answers
-
User1759999623 posted
You don't actually remove the cookie. You have to force the cookie to expire so that when it is read on the client, it will be passed its expiration date and will be removed. Then, when you go back to the server on your next request, the cookie will no longer be available.
By deleting the cookie on the server, you only force your next request to send back the cookie that's still there, thus having the cookie come back to the server.
Set the Expires property on your cookie to either DateTime.Now or something like DateTime.Now.AddSeconds(-60) so that it will be clearly passed the expiration time when the cookie returns to the client.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 3, 2015 1:05 PM -
User-271186128 posted
Hi volar5,
As Careed said, you didn't actually delete the cookie. As for delete a Cookie, we could set the cookie's expiration date to a time in the past. Like this:
If (Not Request.Cookies("UserSettings") Is Nothing) Then Dim myCookie As HttpCookie myCookie = New HttpCookie("UserSettings") myCookie.Expires = DateTime.Now.AddDays(-1D) Response.Cookies.Add(myCookie) End If
For more details, please refer to this articles.
https://msdn.microsoft.com/en-us/library/ms178195(v=vs.100).aspx
Best Regards,
Dillion- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 3, 2015 9:17 PM -
User1256512446 posted
Hi:
Thanks for the reply. At last I found the solution.
Request.Cookies.Remove("cuenta") Response.Cookies("cuenta").Expires = DateTime.Now.AddDays(-1D)
I wonder why have I to put the request.cookies.remove("cuenta")
Thanks again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 4, 2015 3:41 AM
All replies
-
User1759999623 posted
You don't actually remove the cookie. You have to force the cookie to expire so that when it is read on the client, it will be passed its expiration date and will be removed. Then, when you go back to the server on your next request, the cookie will no longer be available.
By deleting the cookie on the server, you only force your next request to send back the cookie that's still there, thus having the cookie come back to the server.
Set the Expires property on your cookie to either DateTime.Now or something like DateTime.Now.AddSeconds(-60) so that it will be clearly passed the expiration time when the cookie returns to the client.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 3, 2015 1:05 PM -
User-271186128 posted
Hi volar5,
As Careed said, you didn't actually delete the cookie. As for delete a Cookie, we could set the cookie's expiration date to a time in the past. Like this:
If (Not Request.Cookies("UserSettings") Is Nothing) Then Dim myCookie As HttpCookie myCookie = New HttpCookie("UserSettings") myCookie.Expires = DateTime.Now.AddDays(-1D) Response.Cookies.Add(myCookie) End If
For more details, please refer to this articles.
https://msdn.microsoft.com/en-us/library/ms178195(v=vs.100).aspx
Best Regards,
Dillion- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 3, 2015 9:17 PM -
User1256512446 posted
Hi:
Thanks for the reply. At last I found the solution.
Request.Cookies.Remove("cuenta") Response.Cookies("cuenta").Expires = DateTime.Now.AddDays(-1D)
I wonder why have I to put the request.cookies.remove("cuenta")
Thanks again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 4, 2015 3:41 AM