get,set ,写入读取cookies--[ASP.NET]
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace demo5 { public partial class hanshu : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ////get方式获取服务器数据,安全性低 string id = Request.QueryString["name"]; string age = Request.QueryString["age"]; Response.Write(id + "<br>" + age);
//好厉害,写给不放弃,把post和get弄清楚的自己!good girl //post方式发送服务器数据,安全性高,需要点击等事件触发来进行, string aa = Request.Form["name"]; string bb = Request.Form["age"]; Response.Write(aa + "<br>" + bb); Response.Write("你使用的是" + Request.RequestType + "方式传送数据"); } protected void Button1_Click(object sender, EventArgs e) { //获取服务器环境变量 Response.Write("当前网页的虚拟路径是:"+Request.ServerVariables["url"]); Response.Write("<br>当前网页虚拟路径是:"+Request.RawUrl); Response.Write("<br>实际路径:"+Request.ServerVariables["path_translated"]); Response.Write("<br>实际路径:" + Request.PhysicalPath); Response.Write("<br>服务器名:"+Request .ServerVariables["server_name"]); Response.Write("<br>服务器IP:"+Request.UserHostAddress); //获取浏览器环境变量 Response.Write("<br>这个浏览器是否支持背景音乐:"+Request.Browser .BackgroundSounds ); Response.Write("<br>这个浏览器是否支持框架:"+Request.Browser.Frames ); Response.Write("<br>客户用的是什么系统:" +Request.Browser.Platform ); } protected void Button2_Click(object sender, EventArgs e) { //写入cookies HttpCookie nc = new HttpCookie("newcookie");//声明cookie对象 nc.Values["name"] = "天轰穿";//cookie的名字 nc.Values["age"] = "27"; nc.Values["dt"] = DateTime.Now.ToString(); Response.Cookies.Add(nc);//把当前创建的对象写入cookie Response.Write("Cookie写入成功"); } protected void Button3_Click(object sender, EventArgs e) {//读取cookie HttpCookie getcook = Request.Cookies["newcookie"]; Response.Write (getcook.Values["name"]); Response.Write("<br>"+getcook.Values ["age"]); Response.Write("<br>"+getcook.Values ["dt"]); } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。