zoukankan      html  css  js  c++  java
  • session传值取值

    protected void Page_Load(object sender, EventArgs e)
    {
    //判断session是否为空
    if (Session["user"]!=null)
    {
    //UserInfo us = new UserInfo(string username,string pwd, string email);
    UserInfo us = (UserInfo)Session["user"];
    this.username.Text = us.Username;
    this.pwd.Text = us.Pwd;
    // string s = (string)Session["User"];
    Response.Write(" <script>alert('您已经注册登陆了,即将返回首页!');</script>");
    Response.Write(" <script>alert('跳转中');window.location.href='index.aspx';</script>");

    }
    else
    {
    Session["user"] = null;
    }

    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
    string usernams = this.username.Text;
    string pwd = this.username.Text;
    if (Session["user"]!=null)
    {
    UserInfo us=(UserInfo)Session["user"];

    //假如session为空,证明没有注册,对于这种人,密码账号你就瞎写,让他注册才能打开
    if (us.Username==usernams&&us.Pwd==pwd)
    {
    Response.Write(" <script>alert('跳转中');window.location.href='index.aspx';</script>");

    }
    else
    {
    Response.Write("<script>aleat('密码错误')</script>");
    }
    }
    else
    {
    if ( usernams!="用户名你猜不到" && pwd!="密码你猜不到")
    {
    Response.Write("<script>alert('密码错误')</script>");
    }
    else
    {
    Response.Write(" <script>alert('跳转中');window.location.href='index.aspx';</script>");


    }
    }

    // UserInfo us = new UserInfo
    // {
    // Username = (string)Session["User"]
    // };

    // Response.Write(" <script>alert('" +us. Username + "');</script>");
    //}
    //string ua=Session["user"];

    //UserInfo us = new UserInfo();

    //string s = (string)Session["User"] ;

    // Response.Write(us.Pwd);
    }
    }

    ------------------登陆界面------------

    protected void Button1_Click(object sender, EventArgs e)
    {
    UserInfo user = new UserInfo();
    user.Username = this.username.Text;

    user.Pwd = this.pwd.Text;
    user.Email = this.email.Text;
    Session["user"] = user;


    // Response.Write(user.Pwd);
    Response.Write(" <script>alert('注册成功,跳转中');window.location.href='index.aspx';</script>");


    }

     -----------注册-----------------------

    //由于session的数据放在服务器,不能大量占用资源,创建个类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    /// <summary>
    /// UserInfo 的摘要说明
    /// </summary>
    public class UserInfo
    {
    public UserInfo()
    {


    }

    /// <summary>
    /// 创建用户名,密码,邮箱变量,存数据,封装变量,构造函数
    /// </summary>

    private string username;

    public string Username
    {
    get { return username; }
    set { username = value; }
    }
    private string pwd;

    public string Pwd
    {
    get { return pwd; }
    set { pwd = value; }
    }
    private string email;

    public string Email
    {
    get { return email; }
    set { email = value; }
    }


    public UserInfo(string username, string pwd, string Email) {

    Username = username;
    Pwd = pwd;
    Email = email;
    }
    }

    END

  • 相关阅读:
    TensorFLow手写字识别深度学习网络分析详解
    使用MSBUILD 构建时出错 error MSB3086: 任务未能使用 SdkToolsPath“”或注册表项“XXX”找到“LC.exe”,请确保已设置 SdkToolsPath。
    解决Win7启动时出现“windows未能启动。原因可能是最近更改了硬件或软件”的问题
    SSH安装篇之——SecureCRT连接(内网和外网)虚拟机中的Linux系统(Ubuntu)
    git push 冲突
    ubuntu快捷键收集
    ubuntu中wine下安装QQ
    ubuntu下安装无线网卡去驱动Qualcomm-Atheros-QCA9377
    spring mvc添加静态资源访问时@Controller无效的解决
    git更新到远程服务器代码
  • 原文地址:https://www.cnblogs.com/whatarey/p/8612780.html
Copyright © 2011-2022 走看看