网站开发2008/太原seo外包公司
Request.Form:获取以POST方式提交的数据。
Request.QueryString:获取地址栏参数(以GET方式提交的数据)。
Request:包含以上两种方式(优先获取GET方式提交的数据),它会在QueryString、Form、ServerVariable中都搜寻一遍。
Request.QueryString:获取地址栏参数(以GET方式提交的数据)。
Request:包含以上两种方式(优先获取GET方式提交的数据),它会在QueryString、Form、ServerVariable中都搜寻一遍。
有时候会得到不同的结果。如果仅仅需要Form中的数据,但是使用了Request而不是Request.Form,那么程序将在QueryString、ServerVariable中也搜寻一遍。如果其中有同名的项,就得到不一样的结果。
在asp.net编程中,QueryString、Form、Cookie是三种比较常见的接收客户端参数的方式。QueryString:接收包含在url中的参数。Form:接收表单数据。Cookie可以获取会话状态中保存的信息(大部分情况下用来存储用户信息)。除了这些外,HttpRequest还提供了ServerVariables来让我们获取一些来自web服务器变量。
Request.Params是NameValueCollection键值对类型的只读属性,在FillInParamsCollection方法中,将QueryString,Form,Cookies,ServerVariables加入到了字段中。Params[key]会取到QueryString和cookie里面的值了。
可以看到Request[key]的实现方式,查找顺序是QueryString,Form,Cookies,ServerVariables,直到找到然后直接返回。
Params的实现
// Params collection - combination of query string, form, server vars// Gets a combined collection of QueryString+Form+ ServerVariable+Cookies.public NameValueCollection Params {get {if (HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Low))return GetParams();elsereturn GetParamsWithDemand();}}
private NameValueCollection GetParams() {if (_params == null) {_params = new HttpValueCollection(64);FillInParamsCollection();_params.MakeReadOnly();}return _params;}[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Low)]private NameValueCollection GetParamsWithDemand(){return GetParams();}
// Params collection supportprivate void FillInParamsCollection() {_params.Add(this.QueryString);_params.Add(this.Form);_params.Add(this.Cookies);_params.Add(this.ServerVariables);}
equest[key]的实现
// Default property that goes through the collections// QueryString, Form, Cookies, ClientCertificate and ServerVariablespublic String this[String key] {get {String s;s = QueryString[key];if (s != null)return s;s = Form[key];if (s != null)return s;HttpCookie c = Cookies[key];if (c != null)return c.Value;s = ServerVariables[key];if (s != null)return s;return null;}}