Solved

ASP.NET remove cookie

Posted on 2007-12-06
3
698 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save ms data to server side. 19 59
edit .asp files 5 47
Google Maps with Webforms 1 29
Securing WEBAPI on Azure 2 19
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 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