Request[]与Request.Params[] 差别
Request[]与Request.Params[] ,这二个属性都可以让我们方便地根据一个KEY去【同时搜索】QueryString、Form、Cookies 或 ServerVariables这4个集合
这二个属性唯一不同的是: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();
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
Request[]与Request.Params[] 差别的更多相关文章
- 客户端的数据来源:QueryString, Form, Cookie Request[]与Request.Params[]
在ASP.NET编程中,有三个比较常见的来自于客户端的数据来源:QueryString, Form, Cookie . 我们可以在HttpRequest中访问这三大对象. QueryString: 获 ...
- 细说Request与Request.Params
在ASP.NET编程中,有三个比较常见的来自于客户端的数据来源:QueryString, Form, Cookie .我们可以在HttpRequest中访问这三大对象,比如,可以从QueryStrin ...
- C#中 Request, Request.params , Request.querystring , Request.Form 区别 与联系用法
C#中 Request, Request.params , Request.querystring , Request.Form 区别 与联系用法? Request.params , Request ...
- csharp: Request.Form,Request.QueryString,Request.Params,Request.Cookies
/// <summary> /// Request.Form,Request.QueryString,Request.Params /// http://msdn.microsoft.co ...
- String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- basePath = request.getScheme()+"://"+request.getServerName()+":"+r
basePath = request.getScheme()+"://"+request.getServerName()+":"+r (2014-06-30 1 ...
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+pat----------<base>元素有关
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. ...
- request.get request.GET……
发现他们是不同的. 报错: AttributeError at /add/ 'WSGIRequest' object has no attribute 'get' Request Method: GE ...
- JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)
本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...
随机推荐
- Could not find class 'org.ksoap2.serialization.SoapObject
Could not find class 'org.ksoap2.serialization.SoapObject工程编译没问题,一在模拟器运行就报错! 这是由于ADT版本过高引发的问题,解决办法: ...
- 删除SVN被锁定文件
svn的working copylocked这种情况大多是因为上次svn命令执行失败且被锁定了. 如果cleanup没有效果的话只好手动删除锁定文件. cd 到svn项目目录下,然后执行命令:del ...
- Linux 简单按键中断处理流程
中断处理程序中不能延时.休眠之类的,一定要最快速.高效的执行完. // 功能:申请中断 // 参数1:中断号码,通过宏 IRA_EINT(x) 获取 // 参数2:中断的处理函数,填函数名 // 参数 ...
- zabbix监控的配置
ZABBIX监控的操作步骤有两个! 首先登录到zabbix 的主界面在configuration---host---create host在如上的host 创建界面中 主要是输入被监测的server的 ...
- Linux_LVM Couldn't find device with uuid
Linux LVM commands result in Couldn't find device with uuid Couldn't find all physical volumes for v ...
- AngularJS:Select
ylbtech-AngularJS:Select 1.返回顶部 1. AngularJS Select(选择框) AngularJS 可以使用数组或对象创建一个下拉列表选项. 使用 ng-option ...
- Java开发进阶技能(附文章引用链接)
一.玩转源码 1.Java+Selenium3方法篇0-如何在Eclipse上查看Selenium源码 (在github上下载源码)
- 1024 Palindromic Number
题意: 给出一个数N(N<=10^10),最多可操作K次(K<=100),每次操作为这个数和其反转之后的数相加,若得到的结果为回文数,则输出:若在K次迭代后仍然不是回文数,在输出第K次操作 ...
- thinkphp中的volist标签
属性: name(必须):要输出的数据模板变量 id(必须):循环变量 offset(可选):要输出数据的offset length(可选):输出数据的长度 key(可选):循环的key变量,默认值为 ...
- python学习(四) 字典:当索引不好用时
第四章 字典:当索引不好用时 4.1 字典的使用 字典的适用场景: 表示一个游戏棋盘的状态,每个键都是由坐标值组成的元组: 存储文件修改时间,用文件名作为键: 数字电话/地址簿 4.2 创建和使用字典 ...