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

  • 相关阅读:
    Bootstrap学习
    Bootstrap学习
    Windows下Apache+Django+mod_wsgi的static和media问题处理
    Windows编译安装mod_wsgi,配合使用Django+Apahce
    Bootstrap学习
    Chapter 21_4 捕获
    Chapter 21_3 模式
    新发现的一些C函数
    Chapter 21_2 模式匹配函数
    Chapter 21_1 字符串函数
  • 原文地址:https://www.cnblogs.com/whatarey/p/8612780.html
Copyright © 2011-2022 走看看