session 和cookie
来源:互联网 发布:算法导论吧 编辑:程序博客网 时间:2024/05/16 07:24
1.Session的小例子
html页面:
<span style="font-size:24px;"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Seession.aspx.cs" Inherits="Session实验.Seession" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title></head><body> <form id="form1" runat="server"> <div> <asp:Label ID="Label2" runat="server" Text="label2"></asp:Label> </div> <p> <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label> </p> <p> <asp:RadioButton ID="rdbStudent" runat="server" Text="考生" GroupName="1" AutoPostBack="True" OnCheckedChanged="rdbStudent_CheckedChanged" /> <asp:RadioButton ID="rdbWorker" runat="server" Text="考务人员" GroupName="1" /> </p> <p> <asp:Label ID="Label4" runat="server" Text="账号"></asp:Label> <asp:TextBox ID="txtAccount" runat="server" style="margin-bottom: 5px" ></asp:TextBox> </p> <p> <asp:Label ID="Label3" runat="server" Text="密码"></asp:Label> <asp:TextBox ID="txtPassWord" runat="server" style="margin-bottom: 5px" ></asp:TextBox> </p> <p> <asp:Button ID="btnLogin" runat="server" OnClick="Button1_Click" Text="登录" /> </p> </form></body></html></span>
后台C#代码:
<span style="font-size:24px;">using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Session实验{ public partial class Seession : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.IsWho(); } protected void redirectpatch( string loginName,string passWord) { if (rdbWorker.Checked==true ) { string userInfo = loginName; if (loginName == "") { Label2.Text = "账号不能为空"; } else { //Session["userInfo"] = new Seession(); Session["loginname"] = userInfo; Session["Password"] = passWord; } } if(rdbStudent.Checked==true ) { Label1.Text = "当前账户是考生,若您为考务人员请输入账户后登录"; Session["loginname"] = null; } } protected void Button1_Click(object sender, EventArgs e) { this.redirectpatch(txtAccount.Text,txtPassWord.Text); this.IsWho(); } protected void IsWho() { if (Session["loginname"] != null) { Label1.Text = "当前登录的是考务人员,用户名:" +(string)Session["loginname"]; } else { Label1.Text = "当前账户是考生,若您为考务人员请输入账户后登录"; } } protected void rdbStudent_CheckedChanged(object sender, EventArgs e) { txtAccount.Text = ""; txtPassWord.Text = ""; } }}</span>
效果图:
Cookie的小例子
protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //读取Cookie HttpCookie getcook = Request.Cookies["newcookie"]; Response.Write(HttpUtility.UrlDecode(getcook.Values["name"])); Response.Write("<br>" + (getcook.Values["age"])); Response.Write("<br>" + getcook.Values["dt"]); //Response.Write("<br>" + getcook.Values["name"]); } protected void Button2_Click(object sender, EventArgs e) { HttpCookie nc = new HttpCookie("newcookie"); nc.Values["name"] = HttpUtility.UrlEncode("天轰穿"); nc.Values["age"] = "27"; nc.Values["dt"] = DateTime.Now.ToString(); Response.Cookies.Add(nc); Response.Write("Cookie写入成功!"); } }
0 0
- session和cookie
- Cookie和Session专题
- Cookie和Session专题
- Cookie和Session专题
- Cookie和Session专题
- 关于Session和Cookie
- Cookie和Session专题
- session 和 cookie
- Cookie和Session专题
- cookie和session
- 浅谈Session和Cookie
- Cookie和Session专题
- Cookie和Session专题
- Cookie和Session专题
- Cookie和Session专题
- Cookie和Session专题
- Cookie和session
- cookie和session关系
- 我的校招——同花顺
- 打造自定义弹出框
- chrome插件开发之:关于处理定时下单的时间点的处理问题
- BZOJ2795/POI2012 A horrible poem
- 【机器学习】01-K-means
- session 和cookie
- nyoj815三角形(已知三角形的三边长或三顶点坐标求面积)&& nyoj68三点顺序(向量叉积)
- HihoCoder 1258(2015 Asia Beijing Regional Contest)
- 快速傅里叶变换(FFT)(下)
- 应用层
- centos 安装 docker 及基础命令使用
- 欢迎使用CSDN-markdown编辑器
- JZOJ 4817 【NOIP2016提高A组五校联考4】square
- eclipse导入项目乱码