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