惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
Vercel News
Vercel News
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
T
Threatpost
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
I
Intezer
P
Privacy International News Feed
D
Docker
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
M
MIT News - Artificial intelligence
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
A
Arctic Wolf
IT之家
IT之家
S
SegmentFault 最新的问题
S
Securelist
博客园 - 叶小钗
N
News and Events Feed by Topic
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
GbyAI
GbyAI
AI
AI
Y
Y Combinator Blog
WordPress大学
WordPress大学
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
N
News | PayPal Newsroom
The Cloudflare Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
I
InfoQ

博客园 - 数码幽灵

[转贴] 网络硬盘“G宝盘”使用体验 - 数码幽灵 - 博客园 个人拼图 有关Web项目使用EnterpriseLibrary的Sercurity问题 - 数码幽灵 - 博客园 关于使用VS.Net2003调试器出现的问题及相关解决方法 关于JavaScript一次提交多个Form出现的问题 看到关于Zope的一些东西 关于SmartClient 与 游戏开发的一点想法 今天看到AppForge的产品 Base4.Net 即将推出 V1.0 WS-Security学习 使用Base4.Net进行项目开发中的问题 发现了C-Omega Essential ASP.NET 读书笔记--Configuration Essential ASP.NET 读书笔记--WebForm Essential ASP.NET 读书笔记--基础 Visual Studio 2005 Express Download Test Driven C# 读书笔记(下) Test Driven C# 读书笔记(上) 每个.Net开发者现在应该下载的十个必备工具!
关于Alex 的 ProcessContext
数码幽灵 · 2005-04-30 · via 博客园 - 数码幽灵

  1using System;
  2using System.Web;
  3using System.Web.UI;
  4using System.Collections;
  5
  6namespace Base4.Web.UI
  7{
  8    /// <summary>
  9    /// This class allows you to move data around (without using a database) between Postbacks and Redirects
 10    /// that are part of the same process and working with the same data.
 11    /// </summary>

 12    public class ProcessContext
 13    {
 14        public static ProcessContext Current
 15        {
 16            get
 17            {
 18                //The overhead of creating a ProcessContext is minimal since it is just a proxy to the real data
 19                //the reason we cache it in the HttpContext is that if we construct a new ProcessContext on each
 20                //Call to ProcessContext.Current then we call RegisterHiddenField more than once per request
 21                //which is dangerous as we may end up storing our data against the wrong ID!
 22                ProcessContext current = HttpContext.Current.Items["__PROCESSCONTEXT"as ProcessContext;
 23                if (current == null)
 24                {
 25                    current = new ProcessContext();
 26                    HttpContext.Current.Items["__PROCESSCONTEXT"= current;
 27                }

 28                return current;    
 29            }

 30        }

 31        public static string CurrentProcessID
 32        {
 33            get
 34            {
 35                return Current.ProcessID;
 36            }

 37        }

 38        protected string _processID = null;
 39        protected Hashtable _items = null;
 40
 41        /// <summary>
 42        /// When the ProcessContext is constructed so postbacks function okay without a QUERYSTRING
 43        /// redirect this Registers a Hidden Field to store the ProcessID in the form.
 44        /// </summary>

 45        protected ProcessContext()
 46        {
 47            (HttpContext.Current.Handler as Page).RegisterHiddenField("__PROCESSID",ProcessID);
 48        }

 49        /// <summary>
 50        /// Accesses the Hashtable associated with this ProcessContext.
 51        /// It creates a new Hashtable if not found. The Hashtable is stored in the users Session
 52        /// keyed on the ProcessContext.ProcessID
 53        /// </summary>

 54        public Hashtable Items
 55        {
 56            get
 57            {
 58                if (_items == null)
 59                {
 60                    _items = HttpContext.Current.Session[ProcessID] as Hashtable;
 61                    if (_items == null
 62                    {
 63                        _items = new Hashtable();
 64                        HttpContext.Current.Session[ProcessID] = _items;
 65                    }

 66                }

 67                return _items;
 68            }

 69        }

 70        /// <summary>
 71        /// Figures out what the ProcessID of the current ProcessContext is
 72        /// Checking in order -> QueryString, __PROCESSID field, or creating a new GUID
 73        /// </summary>

 74        public string ProcessID
 75        {
 76            get
 77            {
 78                if (_processID == null)
 79                {
 80                    _processID = HttpContext.Current.Request.QueryString["ProcessID"as string;
 81                    if (_processID == null)
 82                    {
 83                        _processID = HttpContext.Current.Request.Form["__PROCESSID"as string;
 84                        if (_processID == null)
 85                        {
 86                            _processID = Guid.NewGuid().ToString();
 87                        }

 88                    }

 89                }

 90                return _processID;
 91            }

 92        }

 93        /// <summary>
 94        /// Convenience access to this.Items[key] using this[key]
 95        /// </summary>

 96        public object this[object key]
 97        {
 98            get
 99            {
100                return Items[key];
101            }

102            set
103            {
104                Items[key] = value;
105            }

106        }

107        /// <summary>
108        /// Used to discard all data associated with this process
109        /// </summary>

110        public void Discard()
111        {
112            HttpContext.Current.Session.Remove(ProcessID);
113        }

114        /// <summary>
115        /// Used to empty the hashtable associated with this process
116        /// </summary>

117        public void Clear()
118        {
119            Items.Clear();
120        }

121        /// <summary>
122        /// Used to decorate a URL with the ProcessID so the ProcessContext
123        /// can be transfered to that URL
124        /// </summary>
125        /// <param name="url"></param>

126        public string AttachProcessToUrl(string url)
127        {
128            if (url.IndexOf("?"== -1
129                url = url + "?";
130            else
131                url = url + "&";
132            url += string.Format("ProcessID={0}",ProcessID);
133            return url;
134        }

135        /// <summary>
136        /// Used to redirect to the URL provided and transfer the ProcessContext
137        /// to that URL too.
138        /// </summary>
139        /// <param name="url"></param>
140        /// <param name="endRequest"></param>

141        public void Redirect(string url, bool endRequest)
142        {
143            AttachProcessToUrl(url);
144            HttpContext.Current.Response.Redirect(url,endRequest);
145        }

146    }

147}

148