【发布时间】:2009-10-27 19:02:02
【问题描述】:
如果您通过 Request[key] 对 Request 的项目进行简单的索引,它会在 4 locations 中查找。顺序是什么?有人对该页面的“Cookies、ServerVariables、Form 和 QueryString”进行了猜测。有人有确切消息么?文档将是一个奖励:)
【问题讨论】:
标签: c# asp.net request httprequest
如果您通过 Request[key] 对 Request 的项目进行简单的索引,它会在 4 locations 中查找。顺序是什么?有人对该页面的“Cookies、ServerVariables、Form 和 QueryString”进行了猜测。有人有确切消息么?文档将是一个奖励:)
【问题讨论】:
标签: c# asp.net request httprequest
public string this[string key] { get; }
声明类型:System.Web.HttpRequest 程序集:System.Web, 版本=2.0.0.0
public string this[string key]
{
get
{
string str = this.QueryString[key];
if (str != null)
{
return str;
}
str = this.Form[key];
if (str != null)
{
return str;
}
HttpCookie cookie = this.Cookies[key];
if (cookie != null)
{
return cookie.Value;
}
str = this.ServerVariables[key];
if (str != null)
{
return str;
}
return null;
}
}
【讨论】:
只需使用Reflector,您就可以自己查看。顺序是 QueryString、Form、Cookies,然后是 ServerVariables。
【讨论】:
这是来自ASP site,但它仍然适用于 ASP.NET:
所有请求对象变量都可以 通过调用直接访问 请求(变量)没有 集合名称。在这种情况下,网络 服务器搜索集合中的 以下顺序:
- 查询字符串
- 表格
- Cookie
- 客户证书
- 服务器变量
【讨论】: