zoukankan      html  css  js  c++  java
  • 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"]); } } }

      

  • 相关阅读:
    ASP.NET服务器控件开发(4)复合控件
    C#特性对象集合初始化器
    C#特性匿名类型与隐式类型局部变量
    在Handler中使用Session
    使用 UDPClient 生成聊天客户端
    当下10大最热门的网站开发技术
    C#特性扩展方法
    50个非常有用的PHP工具
    c# 调用.bat文件
    c# 特性/属性(Attribute) 以及使用反射查看自定义特性
  • 原文地址:https://www.cnblogs.com/wangmei/p/4476796.html
Copyright © 2011-2022 走看看