Reputation: 7589
When I access the Request object as a collection, where does it get it's data from?
For example I know
Request["someKey"]
will return the value of either
Request.QueryString["someKey"]
or
Request.Form["someKey"]
depending on which is set.
Are any other collections searched (cookies, session)?
What happens is the key value pair exists in several of the collections?
I took a look in MSDN, but couldn't find much info.
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.request
Thanks for the help!
Upvotes: 0
Views: 121
Reputation: 8748
If you decompile this assembly and take a look at the source, it will look in QueryString
, then Form
, then Cookies
, then ServerVariables
, before finally returning null
if none of them contain the item.
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;
}
}
}
Upvotes: 1