📄 login.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
//51aspx
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//初始化Session对象
Session["UserID"] = "";
Session["Level"] = "";
Session["UserName"] = "";
if (!IsPostBack)
{
HttpCookie mycookie = Request.Cookies["myname"];
if (mycookie != null)
{
txtname.Text = mycookie.Values["name"].ToString();
}
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
//判断验证码是否正确
if (Session["CheckCode"].ToString() == txtyzm.Text.Trim().ToUpper())
{
PublicClass.UserModel user = new PublicClass.UserModel();
user.UserName = txtname.Text;
user.PassWord = txtpwd.Text;
BLL.T_User login = new BLL.T_User();
login.User = user;
int i = login.UserLogin();
switch (i)
{
case 0:
{
//写入Cookie
if (cbName.Checked==true)
{
HttpCookie mycookie = new HttpCookie("myname");
mycookie.Expires = DateTime.Now.AddDays(1);
mycookie.Values["name"] = txtname.Text;
Response.Cookies.Add(mycookie);
}
//设置Session
Session["UserID"] = user.UserID;
Session["UserName"] = user.UserName;
Session["Level"] = user.Level;
//根据权限跳转页面
if (Session["Level"].ToString()=="1")
Response.Redirect("UserMan.aspx");
if (Session["Level"].ToString() == "2")
Response.Redirect("BorrowMan.aspx");
break;
}
case -1:
{
Label3.Text = "该用户不存在!";
break;
}
case 100:
{
Label3.Text = "用户密码错误";
break;
}
}
}
else
{
Label3.Text = "验证码错误";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -