Request[]与Request.Params[] 差别
2016-04-19 13:25
330 查看
Request[]与Request.Params[] ,这二个属性都可以让我们方便地根据一个KEY去【同时搜索】QueryString、Form、Cookies 或 ServerVariables这4个集合
这二个属性唯一不同的是:Item是依次访问这4个集合,找到就返回结果,而Params是在访问时,先将4个集合的数据合并到一个新集合(集合不存在时创建), 然后再查找指定的结果。
Request[]实现原理(.net源代码)
Request.Params[]源码
参考网页http://www.cnblogs.com/fish-li/archive/2011/12/06/2278463.html
这二个属性唯一不同的是:Item是依次访问这4个集合,找到就返回结果,而Params是在访问时,先将4个集合的数据合并到一个新集合(集合不存在时创建), 然后再查找指定的结果。
Request[]实现原理(.net源代码)
// System.Web.HttpRequest /// <summary>Gets the specified object from the <see cref="P:System.Web.HttpRequest.QueryString" />, <see cref="P:System.Web.HttpRequest.Form" />, <see cref="P:System.Web.HttpRequest.Cookies" />, or <see cref="P:System.Web.HttpRequest.ServerVariables" /> collections.</summary> /// <returns>The <see cref="P:System.Web.HttpRequest.QueryString" />, <see cref="P:System.Web.HttpRequest.Form" />, <see cref="P:System.Web.HttpRequest.Cookies" />, or <see cref="P:System.Web.HttpRequest.ServerVariables" /> collection member specified in the <paramref name="key" /> parameter. If the specified <paramref name="key" /> is not found, then null is returned.</returns> /// <param name="key">The name of the collection member to get. </param> public string this[string key] { get { string text = this.QueryString[key]; if (text != null) { return text; } text = this.Form[key]; if (text != null) { return text; } HttpCookie httpCookie = this.Cookies[key]; if (httpCookie != null) { return httpCookie.Value; } text = this.ServerVariables[key]; if (text != null) { return text; } return null; } }
Request.Params[]源码
// System.Web.HttpRequest /// <summary>Gets a combined collection of <see cref="P:System.Web.HttpRequest.QueryString" />, <see cref="P:System.Web.HttpRequest.Form" />, <see cref="P:System.Web.HttpRequest.Cookies" />, and <see cref="P:System.Web.HttpRequest.ServerVariables" /> items.</summary> /// <returns>A <see cref="T:System.Collections.Specialized.NameValueCollection" /> object. </returns> public NameValueCollection Params { get { if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Low)) { return this.GetParams(); } return this.GetParamsWithDemand(); } }
// System.Web.HttpRequest private NameValueCollection GetParams() { if (this._params == null) { this._params = new HttpValueCollection(64); this.FillInParamsCollection(); this._params.MakeReadOnly(); } return this._params; }
// System.Web.HttpRequest private void FillInParamsCollection() { this._params.Add(this.QueryString); this._params.Add(this.Form); this._params.Add(this.Cookies); this._params.Add(this.ServerVariables); }
参考网页http://www.cnblogs.com/fish-li/archive/2011/12/06/2278463.html
相关文章推荐
- UI基础
- WITH (NOLOCK) table hint equivalent for MySQL
- 【教程】基于FlashBuilder创建的FLEX项目使用教程精简版
- HDU 5667 Sequence (BestCoder Round #80 1003)——构造矩阵
- 【Arduino官方教程第一辑】示例程序 2-2 按键
- Microsoft Operations Management Suite 集成 SCOM 推荐
- APUE------文件和目录
- dynamic web module 3.0 requires java(项目选择了Dynamic Web module 3.0无法加入到server中)
- iOS UICollectionViewCell上有Button点击实现收藏效果
- ios6新特性之下拉刷新UIRefreshControl
- 使用连接(JOIN)来代替子查询(Sub-Queries) mysql优化系列记录
- 利用priority_queue实现top K
- js下读取或者设置input中的value值
- request.getParameterMap()的使用方法
- UICollectionView
- iOS 隐藏导航栏UINavigationBar黑线
- Integer.valueof()学习之享元模式
- 设置 UISearchBar 输入字体颜色 和 默认字体颜色
- UIScrollview--使用Autolayout添加约束
- UIUITextView设置类似于UITextField的placeholder