How to delete a Cookie in Asp.Net MVC at the click of Logout.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SEhtesham
    New Member
    • Aug 2011
    • 45

    How to delete a Cookie in Asp.Net MVC at the click of Logout.

    Hi,
    I have an Asp.Net MVC application coded in C#.Net.
    I have two users Admin and General User.There is a Home View which is visible to both the users.Once the user logs in there is also a Logout tab.When the user clicks the Logout or Navigates to the Home page it should get log out and the cookies should get clear.He should have to Log In again to access the Authenticated pages.
    Below is how im saving the Cookies.
    Code:
    Cookie.setCookie(Value1,Value2,"Type of User"); 
    Creating the Cookie
    public static void setCookie(Value1,Value2,User)
    {
    HttpCookie MyCookie= new HttpCookie("MyCookie");
    MyCookie["Value1"] = Value1;
    MyCookie["Value2"] = Value2;
    MyCookie["User"] = User.ToString();
    MyCookie.Expires.Add(new TimeSpan(0,30,0));
              HttpContext.Current.Response.Cookies.Add(MyCookie);
    }
    Setting
    MyCookie.Expire s.Add(new TimeSpan(0,30,0 )); will give me 30 mins default time to expire the cookie.
    But i also want to do the same when the user clicks Logout.
    Please guide how can i do this.
Working...