vs.net2005 Request对象详细介绍
1.获取表单提交数据
通常情况下我们分为post(以FORM的形式进行数据的提交,因此在浏览器中是看不到数据信息的,适合与比较传递比较多的数据时使用)和get(通过http进行传递,并以key和value形式出现,在传递数据量很小时可使用)两种方式进行数据的传递.
例子:
get方式:
string id = Request.QueryString["name"];
string age = Request.QueryString["age"];
Response.Write(id + "<br>" + age);
Response.Write("您使用的是"+Request.RequestTyp+"方式传递数据");
post方式:
string id = Request.Form["name"];
string age = Request.Form["age"];
Response.Write(id + "<br>" + age);
Response.Write("您使用的是"+Request.RequestTyp+"方式传递数据");
2.获取服务器环境变量
protected void Button1_Click(object sender,EventArgs e)
{
Response.Write("当前网页虚拟路径是:"+Request.ServerVariables["url"]); //复杂方法
Response.Write("当前网页虚拟路径是:"+Request.RawUrl);
Response.Write("实际路径:"+Request.ServerVariables["path_translated"]);
Response.Write("实际路径"+Request.PhysicalPath);
Response.Wrtie("服务器名:"+Request.ServerVariables["server_name"]);
Response.Write("服务器名:"+Request.UserHostAddress);
}
3.写入Cookie
protected void Button2_Click(object sender,EventArgs e)
{
HttpCookie nc = new HttpCookie("newcookie");
nc.Values["name"] = tony0303;
nc.Values["age"] = 26;
Response.Cookie.Add(nc);
Response.Write("Cookie写入成功!");
}
4.读出Cookie
protected voidButton2_Click(object sender,EventArgs e)
{
HttpCookie nc = new HttpCookie("newcookie");
Response.Write(nc.Values["name"]);
}
通常情况下我们分为post(以FORM的形式进行数据的提交,因此在浏览器中是看不到数据信息的,适合与比较传递比较多的数据时使用)和get(通过http进行传递,并以key和value形式出现,在传递数据量很小时可使用)两种方式进行数据的传递.
例子:
get方式:
string id = Request.QueryString["name"];
string age = Request.QueryString["age"];
Response.Write(id + "<br>" + age);
Response.Write("您使用的是"+Request.RequestTyp+"方式传递数据");
post方式:
string id = Request.Form["name"];
string age = Request.Form["age"];
Response.Write(id + "<br>" + age);
Response.Write("您使用的是"+Request.RequestTyp+"方式传递数据");
2.获取服务器环境变量
protected void Button1_Click(object sender,EventArgs e)
{
Response.Write("当前网页虚拟路径是:"+Request.ServerVariables["url"]); //复杂方法
Response.Write("当前网页虚拟路径是:"+Request.RawUrl);
Response.Write("实际路径:"+Request.ServerVariables["path_translated"]);
Response.Write("实际路径"+Request.PhysicalPath);
Response.Wrtie("服务器名:"+Request.ServerVariables["server_name"]);
Response.Write("服务器名:"+Request.UserHostAddress);
}
3.写入Cookie
protected void Button2_Click(object sender,EventArgs e)
{
HttpCookie nc = new HttpCookie("newcookie");
nc.Values["name"] = tony0303;
nc.Values["age"] = 26;
Response.Cookie.Add(nc);
Response.Write("Cookie写入成功!");
}
4.读出Cookie
protected voidButton2_Click(object sender,EventArgs e)
{
HttpCookie nc = new HttpCookie("newcookie");
Response.Write(nc.Values["name"]);
}