Hi,
I am creating a cookie using the following code:
Dim iharyanacookie As HttpCookie
iharyanacookie = New HttpCookie("username", uid.Text)
Response.Cookies.Add(iharyanacookie)
But how can I delete or destroy a cookies. I using the following code about cookies is still there and working.
Response.Cookies("iharyanacookie").Expires = DateTime.Now.AddYears(-30)
Response.Cookies.Remove("iharyanacookie")
Response.Redirect("http://www.iharyana.com")
Basically the whole page code is:
Imports System.Data.SqlClient
Partial Class WebUserControl
Inherits System.Web.UI.UserControl
Login Button:
Protected Sub login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles login.Click
login_error.Text = ""
Dim conn1 As SqlConnection
Dim comm1 As SqlCommand
Dim reader1 As SqlDataReader
Dim connstring1 As String
connstring1 = ConfigurationManager.ConnectionStrings("iharyana").ConnectionString
conn1 = New SqlConnection(connstring1)
Dim users As String
users = "select password from usermain where username = @username"
comm1 = New SqlCommand(users, conn1)
comm1.Parameters.Add("@username", Data.SqlDbType.VarChar, 20)
comm1.Parameters("@username").Value = uid.Text
conn1.Open()
reader1 = comm1.ExecuteReader
If reader1.Read Then
Dim pass As String
pass = reader1.Item("password")
If (pass = password.Text) Then
'create cookies
Dim iharyanacookie As HttpCookie
iharyanacookie = New HttpCookie("username", uid.Text)
Response.Cookies.Add(iharyanacookie)
Response.Redirect("http://www.iharyana.com")
Else
login_error.Text = "Invalid Login ID or Password! Try Again"
End If
End If
reader1.Close()
conn1.Close()
End Sub
Page Load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim iharyanacookie As HttpCookie
iharyanacookie = Request.Cookies("username")
If iharyanacookie Is Nothing Then
Else
user.Text = "Welcome back <b>" & iharyanacookie.Value & "</b>"
uid.Visible = False
pass.Visible = False
password.Visible = False
login.Visible = False
forgot.Visible = False
sep.Visible = False
reg.Visible = False
my.Visible = True
logout.Visible = True
End If
End Sub
Logout Button:
Protected Sub logout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles logout.Click
Response.Cookies("iharyanacookie").Expires = DateTime.Now.AddYears(-30)
Response.Cookies.Remove("iharyanacookie")
Response.Redirect("http://www.iharyana.com")
End Sub
End Class
Pls pls help.