session传值取值

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

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值