色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

如何實現(xiàn)對上下文(Context)數(shù)據(jù)的統(tǒng)一管理 [提供源代碼下載]

應(yīng)用開發(fā)中,我們經(jīng)常需要設(shè)置一些上下文(Context)信息,這些上下文信息一般基于當(dāng)前的會話(Session),比如當(dāng)前登錄用戶的個人信息;或者基于當(dāng)前方法調(diào)用棧,比如在同一個調(diào)用中涉及的多個層次之間數(shù)據(jù)。在這篇文章中,我創(chuàng)建了一個稱為ApplicationContext的組件,對上下文信息進(jìn)行統(tǒng)一的管理。[Source Code從這里下載]

一、基于CallContext和HttpSessionState的ApplicationContext

如何實現(xiàn)對上下文信息的存儲,對于Web應(yīng)用來說,我們可以借助于HttpSessionState;對于GUI應(yīng)用來講,我們則可以使用CallConext。ApplicationContext完全是借助于這兩者建立起來的,首先來看看其定義:

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Runtime.Remoting.Messaging;
   4: using System.Web;
   5: namespace Artech.ApplicationContexts
   6: {
   7:     [Serializable]
   8:     public class ApplicationContext:Dictionary<string, object>
   9:     {
  10:         public const string ContextKey = "Artech.ApplicationContexts.ApplicationContext";
  11:         
  12:         public static ApplicationContext Current
  13:         {
  14:             get
  15:             {
  16:                 if (null != HttpContext.Current)
  17:                 {
  18:                     if (null == HttpContext.Current.Session[ContextKey])
  19:                     {
  20:                         HttpContext.Current.Session[ContextKey] = new ApplicationContext();
  21:                     }
  22:  
  23:                     return HttpContext.Current.Session[ContextKey] as ApplicationContext;
  24:                 }
  25:  
  26:                 if (null == CallContext.GetData(ContextKey))
  27:                 {
  28:                     CallContext.SetData(ContextKey, new ApplicationContext());
  29:                 }
  30:                 return CallContext.GetData(ContextKey) as ApplicationContext;                
  31:             }
  32:         }        
  33:     }
  34: }

NET技術(shù)如何實現(xiàn)對上下文(Context)數(shù)據(jù)的統(tǒng)一管理 [提供源代碼下載],轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 湄潭县| 安达市| 宣城市| 营山县| 中卫市| 繁峙县| 原阳县| 嘉禾县| 兴安盟| 金平| 黎平县| 玛曲县| 宜章县| 石首市| 宁海县| 孝感市| 航空| 营山县| 台北市| 吉水县| 望奎县| 双桥区| 金坛市| 敦煌市| 枣强县| 河西区| 大同市| 淅川县| 边坝县| 布拖县| 滨州市| 郓城县| 陆川县| 青浦区| 济南市| 穆棱市| 新化县| 龙州县| 来宾市| 茌平县| 江口县|