Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Clear Output Cache from User Control in Asp.Net

$
0
0

i have a user control with a name 

uc_Menu.ascx
. The 
menues
 are loaded dynamically 
Role
 base. So, i inlude it in a user control and cached it like this; 
Note: for testing purpose i have just provide 60 sec cache;
<%@ OutputCache Duration="60" VaryByParam="none" %><td id="Menu"><div id="firstpane" runat="server" class="menu_list"><p class="menu_head"><a href="/forms/Dashboard.aspx"><span style="background: url('/App_Themes/Default/Images/icons/ic_grid.png') no-repeat"></span>
                    DashBoard</a></p></div></td>

The code behind looks like this;

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BulitMenus();
            Response.Write("<h1>" + DateTime.Now.ToString() + "</h1>");
        }
    }

My master page where i have referenced the above user control;

<%@ Register Src="~/UserControls/uc_Menu.ascx" TagPrefix="Ken" TagName="Menu" %><Ken:Menu runat="server" id="Menus" />

Now, when i tested this, it works fine (when page is loaded for the first time, cache worked) 
However, I want to clear the cache when a user click on `LogOff` button (on a master page) because the menus are role base and an admin might give more permissions to user. In that case it is necessary to relode the menus again.
So, How do i clear the cache from a user control
Note: I have also tried this but it deosn't work;
http://aspalliance.com/668_Remove_ASPNET_Page_Output_Cache_Entries
AND

 protected void Lbtn_LogOff_Click(object sender, EventArgs e)
    {

        HttpResponse.RemoveOutputCacheItem("/UserControls/uc_Menu.ascx");
        // this code is copied from a url above which i have included i my question
        HttpContext.Current.Cache.Insert("Pages", DateTime.Now, null,
           System.DateTime.MaxValue, System.TimeSpan.Zero,
           System.Web.Caching.CacheItemPriority.NotRemovable, null);
    
        FormsAuthentication.SignOut();
        Response.Redirect("~/authorization/Login.aspx");
    }








Viewing all articles
Browse latest Browse all 23244

Trending Articles