国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET實現Cache瀏覽器的管理

2024-07-10 12:55:00
字體:
來源:轉載
供稿:網友
對cache進行瀏覽并管理。
  
  <%@ page language="<a 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 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();
   }
  }
  
  //綁定到<a target="_blank">datagrid</a>
  private void bindgrid()
  {
   //創建arraylist來保存cacheditem信息
   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();
  }
  
  //刪除cache項
  protected void grid_itemcommand(object sender, datagridcommandeventargs e)
  {
   hy<a target="_blank">perl</a>ink l = (hyperlink)e.item.findcontrol("cacheitemname");
   //確保我們找到了該項
   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>
  <html>
  <head>
  <title>cache管理器</title>
  <style>
   td,a,p,span {font-size:9pt;}
   .header {background-color:#ededed;text-align:center;font-weight:bold;}
  </style>
  </head>
  <body >
  <form runat="server">
  瀏覽、刪除緩存
  <br/>
  數量:
  <asp:literal id="litcount" runat="server"></asp:literal>
  <br/>
  <asp:linkbutton id="lbremoveall" runat="server">清除全部緩存項</asp:linkbutton>
  <br/>
  <asp:hyperlink id="hlrefresh" text="刷新" runat="server"></asp:hyperlink>
  <br/><br/>
  <asp:datagrid id="dgcacheditems" runat="server" onitemcommand="grid_itemcommand"
   autogeneratecolumns="false" onitemcreated="grid_created">
   <headerstyle cssclass="header"></headerstyle>
   <columns>
   <asp:templatecolumn headertext="數量">
   <itemtemplate>
   <asp:literal id="counter" runat="server" />
   </itemtemplate>
   </asp:templatecolumn>
   <asp:templatecolumn headertext="鍵">
   <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="類型">
   <itemtemplate>
   <asp:literal id="cacheitemdatatype" runat="server"
   text='<%# ((cacheditem)(container.dataitem)).cachetype %>' />
   </itemtemplate>
   </asp:templatecolumn>
   <asp:templatecolumn headertext="刪除">
   <itemtemplate>
   <asp:linkbutton id="removebutton" text="刪除" commandname="removefromcache"
   runat="server" />
   </itemtemplate>
   </asp:templatecolumn>
   </columns>
  </asp:datagrid>
  </form>
  </body>
  </html>
  
  說明:datagrid中用到了hyperlink web控件,是為了方便本站的管理,其它則不必這樣用。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿克苏市| 阳春市| 芜湖县| 清苑县| 凤庆县| 绿春县| 讷河市| 青田县| 攀枝花市| 健康| 沂水县| 莱阳市| 青浦区| 贺兰县| 北流市| 鹤岗市| 长沙县| 枣强县| 虹口区| 扶沟县| 安多县| 汉川市| 丰都县| 长顺县| 雅安市| 大方县| 西昌市| 安岳县| 汤阴县| 眉山市| 青冈县| 安西县| 西峡县| 鄂托克前旗| 昭觉县| 绥江县| 宾阳县| 柞水县| 彭州市| 桦南县| 塘沽区|