Solved

ASP.NET remove cookie

Posted on 2007-12-06
3
699 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

739 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