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

  • 相关阅读:
    redis set
    实现排行榜神器——redis zset
    nginx挂了怎么办
    django 400报错
    项目管理【18】 | 项目进度管理-规划进度管理
    项目管理【17】 | 项目进度管理-进度管理概述
    项目管理【23】 | 项目进度管理-制定进度计划
    移动端开发基础【7】生命周期
    移动端开发案例【7】移动端朋友圈发布显示开发
    移动端开发案例【6】移动端群、用户搜索开发
  • 原文地址:https://www.cnblogs.com/whatarey/p/8612780.html
Copyright © 2011-2022 走看看