Solved

ASP.NET remove cookie

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 40
Get Reply from SSIS to intranet site when finished 3 34
Split in Javascript 5 31
Message not shown 5 33
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

14 Experts available now in Live!

Get 1:1 Help Now