Asp. NET to implement the management of Cache browser
Last Update:2017-02-28
Source: Internet
Author: User
asp.net|cache| Browser to browse and manage cache.
<%@ Page language= "<a href=" http://dev.21tx.com/dotnet/csharp/"target=" _blank ">C#</a>" EnableViewState = "true"%>
<%@ import namespace= "System"%>
<%@ import namespace= "System.Configuration"%>
<%@ import namespace= "System.Collections"%>
<%@ import namespace= "System.Collections.Specialized"%>
<%@ import namespace= "System.Data"%>
<script runat= "Server" >
Http://<a href= "http://dev.21tx.com/web/asp/" target= "_blank" >asp</a>alliance.com/aldotnet/ Examples/cacheviewer.aspx
Http://scottwater.com
private void Page_Load (object sender, System.EventArgs e)
{
if (! IsPostBack)
{
Hlrefresh.navigateurl = Request.rawurl;
Bindgrid ();
}
}
Bind to <a href= "Http://dev.21tx.com/dotnet/aspnet/datagrid/" target= "_blank" >DataGrid</a>
private void Bindgrid ()
{
Create ArrayList to save Cacheditem information
ArrayList al = new ArrayList ();
IDictionaryEnumerator cacheenum = Cache.getenumerator ();
while (Cacheenum.movenext ())
{
Al. ADD (New Cacheditem (CacheEnum.Key.ToString (), CacheEnum.Value.GetType (). ToString ()));
}
Litcount.text = al. Count.tostring ();
Dgcacheditems.datasource = al;
Dgcacheditems.databind ();
}
Delete cache entry
protected void Grid_itemcommand (object sender, DataGridCommandEventArgs e)
{
Hy<a href= "http://dev.21tx.com/web/perl/" target= "_blank" >perl</a>ink L = (HyperLink) E.item.findcontrol ("Cacheitemname");
Make sure we find the item.
if (l!= null)
{
Cache.remove (L.text);
}
This. Bindgrid ();
}
protected void grid_created (object sender, DataGridItemEventArgs e)
{
if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem)
{
((Literal) E.item.findcontrol ("Counter")). Text = (E.item.itemindex + 1). ToString ();
}
}
Private Class Cacheditem
{
Public Cacheditem () {}
Public Cacheditem (String key, String type)
{
This. CacheKey = key;
This. CacheType = type;
}
private string _cachekey;
public string CacheKey
{
get {return this._cachekey;}
set {This._cachekey = value;}
}
private string _cachetype;
public string CacheType
{
get {return this._cachetype;}
set {This._cachetype = value;}
}
}
Remove All
void Lbremoveall_click (object sender, EventArgs e)
{
IDictionaryEnumerator cacheenum = Cache.getenumerator ();
while (Cacheenum.movenext ())
{
Cache.remove (CacheEnum.Key.ToString ());
}
Bindgrid ();
}
</script>
<title>cache Manager </title>
<style>
Td,a,p,span {font-size:9pt;}
. Header {background-color: #EDEDED; text-align:center;font-weight:bold;}
</style>
<body >
<form runat= "Server" >
browsing, deleting caching
<br/>
Number:
<asp:literal id= "Litcount" runat= "Server" ></asp:Literal>
<br/>
<asp:linkbutton id= "Lbremoveall" runat= "Server" > Clear all Cache entries </asp:LinkButton>
<br/>
<asp:hyperlink id= "Hlrefresh" text= "Refresh" runat= "Server" ></asp:HyperLink>
<br/><br/>
<asp:datagrid id= "Dgcacheditems" runat= "Server" onitemcommand= "Grid_itemcommand"
autogeneratecolumns= "False" onitemcreated= "grid_created" >
<Columns>
<asp:templatecolumn headertext= "Quantity" >
<ItemTemplate>
<asp:literal id= "Counter" runat= "Server"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "Key" >
<ItemTemplate>
<asp:hyperlink id= "Cacheitemname" runat= "server" target= "_blank"
Text= ' <%# (cacheditem) (Container.DataItem). CacheKey%> '
NavigateUrl = ' <%# (cacheditem) (Container.DataItem). CacheKey%> '/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "Type" >
<ItemTemplate>
<asp:literal id= "Cacheitemdatatype" runat= "Server"
Text= ' <%# (cacheditem) (Container.DataItem). CacheType%> '/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "Delete" >
<ItemTemplate>
<asp:linkbutton id= "RemoveButton" text= "delete" commandname= "Removefromcache"
runat= "Server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
Description: The DataGrid uses the Hyperlink Web control, is to facilitate the management of the site, others do not need to use this.