?
Solved

ASP.net Logging out - clearing cookies

Posted on 2014-08-28
2
Medium Priority
?
264 Views
Last Modified: 2014-08-28
Hi

I am using the following code to keep a user logged in on my ASP.net site
What code would I use to log them out. I presume that setting DateTime.Now.AddDays(-1)
for all of them would do the trick. Is this the best way

            If chkRememberMe.Checked Then
                Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
                Response.Cookies("Password").Expires = DateTime.Now.AddDays(30)
                Response.Cookies("CompanyIDs").Expires = DateTime.Now.AddDays(30)
            Else
                Response.Cookies("UserName").Expires = DateTime.Now.AddDays(-1)
                Response.Cookies("Password").Expires = DateTime.Now.AddDays(-1)
                Response.Cookies("CompanyIDs").Expires = DateTime.Now.AddDays(-1)
            End If

            Response.Cookies("UserName").Value = txtUserName.Text.Trim
            Response.Cookies("Password").Value = txtPassword.Text.Trim
            Response.Cookies("CompanyIDs").Value = Me.lblCompanyIDs.Text
0
Comment
Question by:Murray Brown
2 Comments
 
LVL 22

Accepted Solution

by:
Tapan Pattanaik earned 2000 total points
ID: 40289906
Hi murbro,

if (Request.Cookies["UserName"] != null)
{
    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);  
}

also use
        Session.Abandon();
        Session.RemoveAll();
        Response.Redirect("~/Login.aspx", false);
0
 

Author Closing Comment

by:Murray Brown
ID: 40291163
Thanks very much
0

Featured Post

Industry Leaders: 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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

621 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