Request.QueryString[""] 与 Request[""] 、 Request.QueryString[""].Tostring()

ASP.net程序是服务器控制的,你打开的网页只是服务器线程池中一个线程的运行结果,所以你即使关闭了网页,应用程序也不会关闭的

1.Request.QueryString["id"] 只能读取通过地址栏参数传递过来的名为id的参数
2.Request["id"]是一个复合功能读取函数。
3.它的优先级顺序为
QueryString > Form > Cookies > ServerVariables(服务器环境变量)
4.Request["id"]会自动按优先级搜索。
5.Request.QueryString["id"](找不到值返回null) Request.QueryString["id"].ToString()(找不到值返回null,null.ToString()会报错)


以下是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;
}
}

<%
foreach (string x in Request.ServerVariables )
{
Response.Write(x + "<br />**" + Request.ServerVariables[x] + "<br/>!!!!");

}
%>
可以遍历所有的服务器环境变量的值。

原文地址:https://www.cnblogs.com/zhubenxi/p/5142551.html