Solved

ASP.NET remove cookie

Posted on 2007-12-06
3
691 Views
Last Modified: 2010-08-05
What is the proper way to remove the cookie immediatley in the ELSE code below?
Dim RememberMe As Boolean

        If ck1.Checked = True Then

            RememberMe = True

        Else

            RememberMe = False

        End If

        If RememberMe = True Then

            'If they choose to remember there account

            Dim c As New System.Web.HttpCookie("royalUser", Trim(txtEmail.Text))

            c.Expires = Now.AddMonths(1)

            HttpContext.Current.Response.Cookies.Add(c)
 

            Dim p As New System.Web.HttpCookie("royalPass", Trim(txtPassword.Text))

            p.Expires = Now.AddMonths(1)

            HttpContext.Current.Response.Cookies.Add(p)

        Else

           
 

        End If

Open in new window

0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 250 total points
ID: 20419727
To remove a cookie, you need to set the expiration date to a past date.  Sometimes I've found just doing this on the server isn't enough, and I've had to write Javascript to delete the cookie on their browser (using the same technique)
0
 
LVL 12

Assisted Solution

by:needo_jee
needo_jee earned 250 total points
ID: 20419735
HttpCookieCollection cookieCols = new HttpCookieCollection();
cookieCols = Request.Cookies;
Request.Cookies.Remove("PASS");
Request.Cookies.Remove("UID");
0
 
LVL 12

Expert Comment

by:needo_jee
ID: 20419789
Dim RememberMe As Boolean
        If ck1.Checked = True Then
            RememberMe = True
        Else
            RememberMe = False
        End If
        If RememberMe = True Then
            'If they choose to remember there account
            Dim c As New System.Web.HttpCookie("royalUser", Trim(txtEmail.Text))
            c.Expires = Now.AddMonths(1)
            HttpContext.Current.Response.Cookies.Add(c)
 
            Dim p As New System.Web.HttpCookie("royalPass", Trim(txtPassword.Text))
            p.Expires = Now.AddMonths(1)
            HttpContext.Current.Response.Cookies.Add(p)
        Else
           
  Dim cookieCols As New HttpCookieCollection
            cookieCols = Request.Cookies
            Request.Cookies.Remove("royalUser")
            Request.Cookies.Remove("royalPass")
        End If
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now