当我将Request对象作为集合访问时,它从哪里获取数据?
例如我知道
Request["someKey"]
将返回
的值Request.QueryString["someKey"]
或
Request.Form["someKey"]
取决于设置的内容。
是否搜索了其他馆藏(Cookie,会话)?
在几个集合中存在键值对会发生什么?
我在MSDN上看了一下,但找不到太多信息。
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.request
感谢您的帮助!
答案 0 :(得分:1)
如果您反编译此程序集并查看源代码,它将在QueryString
,然后Form
,然后Cookies
,然后ServerVariables
中查看,最后返回null
如果它们都不包含该项目。
public string this[string key]
{
get
{
string item = this.QueryString[key];
if (item == null)
{
item = this.Form[key];
if (item == null)
{
HttpCookie httpCookie = this.Cookies[key];
if (httpCookie == null)
{
item = this.ServerVariables[key];
if (item == null)
{
return null;
}
else
{
return item;
}
}
else
{
return httpCookie.Value;
}
}
else
{
return item;
}
}
else
{
return item;
}
}
}