clear Cache when Logout

Last post 01-22-2009 4:23 PM by Afriklink. 10 replies.

Sort Posts:

  • clear Cache when Logout

    01-08-2009, 11:27 AM
    • Member
      99 point Member
    • Afriklink
    • Member since 01-15-2008, 8:43 PM
    • Columbus, Ohio USA
    • Posts 118

    I would like to clear all cache in my Application when user Logout.

    \The website has 2 type of members and when member1 Visit ../department1.aspx and logout, i can still see the page by typing ../departement1.aspx in the Browser

    I try to debug it but it seems like by typing the url in browser, it display the page. But when hit F5 it then bring me to the Login.aspx

    I think this is a Cache issue and i use this at logout.aspx

    protected override void OnLoad( EventArgs e )

    {

     

    base.OnLoad( e );

     

    var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

    if ( authCookie != null )

    {

    authCookie.Expires = DateTime.Now.AddDays( -1 );

    }

    ClearApplicationCache();

    Session.Abandon();

    FormsAuthentication.SignOut();

    FormsAuthentication.RedirectToLoginPage();

    }

    public void ClearApplicationCache()

    {

    List<string> keys = new List<string>();

    // retrieve application Cache enumerator

    IDictionaryEnumerator enumerator = Cache.GetEnumerator();

    // copy all keys that currently exist in Cache

    while (enumerator.MoveNext())

    {

    keys.Add(enumerator.Key.ToString());

    }

    // delete every key from cache

    for (int i = 0; i < keys.Count; i++)

    {

    Cache.Remove(keys[i]);

    }

    }

    But  Still Not working. Any Help?

  • Re: clear Cache when Logout

    01-08-2009, 11:37 AM

    Add the following code in your page & check it

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

     

  • Re: clear Cache when Logout

    01-08-2009, 11:37 AM
    • All-Star
      26,076 point All-Star
    • budugu
    • Member since 01-12-2006, 7:15 PM
    • North Carolina
    • Posts 3,864

    Check this code.. 

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time
     
    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: clear Cache when Logout

    01-08-2009, 11:46 AM
    Answer
    • All-Star
      94,406 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, PH
    • Posts 13,998
    • TrustedFriends-MVPs

    Afriklink:
    I would like to clear all cache in my Application when user Logout.
     

    Check this thread:

    http://forums.asp.net/t/1368940.aspx



    "Code,Beer and Music ~ my way of being a programmer"



  • Re: clear Cache when Logout

    01-08-2009, 11:56 AM
    Answer
    • Member
      99 point Member
    • Afriklink
    • Member since 01-15-2008, 8:43 PM
    • Columbus, Ohio USA
    • Posts 118

    This is what i have but it sstill not working

     

    protected override void OnLoad( EventArgs e )

    {

     

    base.OnLoad( e );

     

    var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

    if ( authCookie != null )

    {

    authCookie.Expires = DateTime.Now.AddDays( -1 );

    }

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Response.Cache.SetExpires(DateTime.Now);

    Session.Abandon();

    FormsAuthentication.SignOut();

    FormsAuthentication.RedirectToLoginPage();

    }

  • Re: clear Cache when Logout

    01-08-2009, 11:58 AM
    • Member
      99 point Member
    • Afriklink
    • Member since 01-15-2008, 8:43 PM
    • Columbus, Ohio USA
    • Posts 118

    Is this suppose to be somewhere else than the logout page?

  • Re: clear Cache when Logout

    01-08-2009, 12:00 PM
    • Star
      14,790 point Star
    • karan@dotnet
    • Member since 09-13-2007, 8:15 PM
    • New York
    • Posts 2,569

    on th log out page itself you can call the above

    Thanks,
    Karan

    ~ Remember To Mark The Post(s) That Helped You As The ANSWER ~
  • Re: clear Cache when Logout

    01-08-2009, 12:01 PM
    • All-Star
      26,076 point All-Star
    • budugu
    • Member since 01-12-2006, 7:15 PM
    • North Carolina
    • Posts 3,864

    Add the code to Page_load of logout page

    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: clear Cache when Logout

    01-08-2009, 12:22 PM
    • Member
      99 point Member
    • Afriklink
    • Member since 01-15-2008, 8:43 PM
    • Columbus, Ohio USA
    • Posts 118

    This code work only if i put it in the masterpage(member area) .

    In the logout i am still getting the same

  • Re: clear Cache when Logout

    01-08-2009, 3:52 PM
    Answer
    • All-Star
      26,076 point All-Star
    • budugu
    • Member since 01-12-2006, 7:15 PM
    • North Carolina
    • Posts 3,864

    Afriklink:
    This code work only if i put it in the masterpage(member area) .

    What's the problem, if  you place that code masterpage area.?

    Afriklink:
    In the logout i am still getting the same

    Because page already cached.

    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: clear Cache when Logout

    01-22-2009, 4:23 PM
    • Member
      99 point Member
    • Afriklink
    • Member since 01-15-2008, 8:43 PM
    • Columbus, Ohio USA
    • Posts 118

    I am getting page timeout now. However the sessionstate is configure in webconfig to have 30 min timeout.

    <sessionState mode="InProc" timeout="30"  . However the page will expire after only 5 minute and log the user out,.

    I don t know if the NoCache is interfering with this timeOut

Page 1 of 1 (11 items)