作业帮 > 综合 > 作业

Request.QueryString["id"]跟Request["id"] 一样的吗

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/15 20:04:01
Request.QueryString["id"]跟Request["id"] 一样的吗
不一样
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" ]的内部实现代码:
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;
}
}