vs.net2005 Request对象详细介绍
2006-09-12 12:03
651 查看
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"]);
}
相关文章推荐
- Request对象详细介绍
- application、session、request、page 4个JSP内置对象详细介绍
- Request对象详细介绍
- 关于servlet的中的request和response两个对象的详细介绍
- Request对象详细介绍
- XMLHttpRequest对象_详细介绍
- Wscript.Shell对象详细介绍!!(5)
- Wscript.Shell 对象详细介绍
- Dom对象和JQuery对象的详细介绍及其区别
- window.event对象详细介绍
- Wscript.Shell 对象详细介绍
- Webform 内置对象 Session对象、Application全局对象,ViewState详细介绍
- 关于httpServletRequest中方法的详细介绍
- window.event对象详细介绍
- Android 通过Intent使用Bundle传递对象详细介绍
- jsp内置对象及方法详细介绍
- XMLHttpRequest对象属性简单介绍
- javascript 内置对象及常见API详细介绍
- js中的json对象详细介绍
- js中的json对象详细介绍