1.Login.aspx登录将登录名赋值入 Session[\"username\"]
protected void btnLogin_Click( sender, EventArgs e)
{
string username = txtUserName.Value.Trim();
string userpassword = txtUserPassword.Value.Trim();
UserEntity model = new UserEntity();
model.Username = username;
model.Password = Utility.MD5(userpassword);
int i = LoginBLL.Login(model);
Response.Write(i);
if (i>0)
{
HttpContext.Current.Session[\"username\"] = username;
HttpContext.Current.Session.Timeout = 7200;
Response.Redirect(\"Index.aspx\");
}
else
{
if (i == -1)
{
lab_errorMsg.InnerText = \"没有此账户!!!\";
txtUserName.Value = \"\";
txtUserPassword.Value = \"\";
}
else
{
txtUserName.Value = \"\";
txtUserPassword.Value = \"\";
lab_errorMsg.InnerText = \"账户或密码错误!!!\";
}
}
}
2.Index.aspx首页判断Session[\"username\"]是否为空,为空跳回Login.aspx
protected void Page_Load( sender, EventArgs e)
{
if (!IsPostBack)
{
if (System.Web.HttpContext.Current.Session[\"username\"] != null)
{
IndexDataBind();
}
else
{
Response.Redirect(\"Login.aspx\");
}
}
}
继续阅读与本文标签相同的文章
-
阿里云服务器搭建一个网站网站建设的基本步骤——部署与发布新手入门
2026-05-18栏目: 教程
-
网络基础技术实践#网络安全基础技术实践课程
2026-05-18栏目: 教程
-
阿里云服务器计算网络增强型实例sn1ne 适合中大型网站及性能要求高的公司业务使用
2026-05-18栏目: 教程
-
前端进阶|第八天 京东笔试题,引用传参赋值无效?
2026-05-18栏目: 教程
-
阿里云弹性伸缩ESS必知必会
2026-05-18栏目: 教程
