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[] 差别的更多相关文章

  1. 客户端的数据来源:QueryString, Form, Cookie Request[]与Request.Params[]

    在ASP.NET编程中,有三个比较常见的来自于客户端的数据来源:QueryString, Form, Cookie . 我们可以在HttpRequest中访问这三大对象. QueryString: 获 ...

  2. 细说Request与Request.Params

    在ASP.NET编程中,有三个比较常见的来自于客户端的数据来源:QueryString, Form, Cookie .我们可以在HttpRequest中访问这三大对象,比如,可以从QueryStrin ...

  3. C#中 Request, Request.params , Request.querystring , Request.Form 区别 与联系用法

    C#中 Request, Request.params , Request.querystring , Request.Form 区别 与联系用法? Request.params , Request ...

  4. csharp: Request.Form,Request.QueryString,Request.Params,Request.Cookies

    /// <summary> /// Request.Form,Request.QueryString,Request.Params /// http://msdn.microsoft.co ...

  5. String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  6. basePath = request.getScheme()+"://"+request.getServerName()+":"+r

    basePath = request.getScheme()+"://"+request.getServerName()+":"+r (2014-06-30 1 ...

  7. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+pat----------<base>元素有关

    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. ...

  8. request.get request.GET……

    发现他们是不同的. 报错: AttributeError at /add/ 'WSGIRequest' object has no attribute 'get' Request Method: GE ...

  9. JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)

    本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...

随机推荐

  1. BZOJ1355:[Baltic2009]Radio Transmission

    浅谈\(KMP\):https://www.cnblogs.com/AKMer/p/10438148.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...

  2. Tomcat服务器下 catalina.out 日志开关

    很多异常在 debug 日志里不会打印,但在 catalina.out 里会打印,比如方法调用找不到,jdk 版本不匹配等.但是打开了该日志开关又会产生一个问题,就是它会哗啦啦的不断急剧膨胀,文件太大 ...

  3. SQL Server 占用CPU较高的解决方法

    触发原因:月底系统结账的时候对ERP的操作较多,有用户反馈系统之间的数据传输很久没有同步.随即到服务器上查看,没有发现有程序导致的问题,看了一下CPU的使用率,发现SQL Server占用率在百分之九 ...

  4. 深入浅出MFC学习笔记 消息

    本章将会对MFC的消息映射和 命令传递机制做深入探讨. MFC规定了消息传递的路线,消息会按照这个路线传递下去,找不到归宿的话就交给DefWindowProc. 在产生窗口之前,如果我们在创建窗口时指 ...

  5. centos7防火墙 启动和关闭

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙.firewall:systemctl start firewalld.service   #启动firewa ...

  6. 家谱处理(30 分)(字符串的处理substr)

    家谱处理(30 分) 人类学研究对于家族很感兴趣,于是研究人员搜集了一些家族的家谱进行研究.实验中,使用计算机处理家谱.为了实现这个目的,研究人员将家谱转换为文本文件.下面为家谱文本文件的实例: Jo ...

  7. 杂项:UN-APP

    ylbtech-杂项:APP 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   7.返回顶部   8.返回顶部   9.返回顶部   10 ...

  8. 网站漏洞扫描并自动化工具-XAttacker

    注:该脚本根据网站的cms类型来扫描,所以推荐用来扫外国的站 运行脚本 ┌─[root@sch01ar]─[/sch01ar/XAttacker] └──╼ #perl XAttacker.pl 询问 ...

  9. ngnix 403 forbidden的解决办法

    1.在网站根目录下新建文件index.html.index.php. 2.主要是修改nginx的配置文件nginx.conf权限为755即可访问.

  10. 图灵机器人,web录音实现自动化交互问答

    一.图灵机器人 介绍 图灵机器人 是以语义技术为核心驱动力的人工智能公司,致力于“让机器理解世界”,产品服务包括机器人开放平台.机器人OS和场景方案. 官方地址为: http://www.tuling ...