test

Request.QueryString["id"] 只能读取通过地址栏参数传递过来的名为id的参数。
Request["id"]是一个复合功能读取函数。
它的优先级顺序为
QueryString > Form > Cookies > ServerVariables

也就是说,如果存在名为id的地址栏参数,Request[ "id" ] 的效果和 Request.QueryString["id"] 是样的。
如果不存在名为id的地址栏参数,Request.QueryString["id"]将会返回空,但是Request[ "id" ]会继续检查是否存在名为id的表单提交元素,
如果不存在,则继续尝试检查名为id的Cookie,如果不存在,继续检查名为id的服务器环境变量。它将最多做出4个尝试,只有四个尝试都失败,才返回空。 以下是Request[ "id" ]的内部实现代码:
publicstringthis[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;
}
returnnull;
}
}
原文地址:https://www.cnblogs.com/aiyp1314/p/2147622.html