最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
.net后台页面统一验证是否登录代码介绍
时间:2017-05-03 编辑:简简单单 来源:一聚教程网
本文实例为大家分享了.net后台页面统一验证是否登录的具体代码,供大家参考,具体内容如下
首先新写一个PageBase类
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Web;
namespaceDepartmentMIS.Web.myclass
{
publicclassPageBase : System.Web.UI.Page
{
publicPageBase()
{
this.Load +=newEventHandler(BasePage_Load);
}
privatevoidBasePage_Load(objectsender, EventArgs e)
{
if(Session["UserNo"] ==null|| Session["UserNo"].ToString() =="")
{
Response.Redirect("~/Login.aspx");
}
}
}
}
Login页面后台部分代码
protectedvoidbtnLogin_Click(objectsender, EventArgs e)
{
if(rblRole.SelectedValue =="1")
{
DataSet ds = AdminBLL.GetList("userName = '"+ tbxUserName.Text.Trim() +"' and password = '"+ tbxPassword.Text.Trim()+"' and isDeleted = 0");
if(ds.Tables[0].Rows.Count == 1)
{
intid = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]);
Session["UserNo"] = ds.Tables[0].Rows[0]["id"];
Session["UserName"] = ds.Tables[0].Rows[0]["userName"];
Response.Redirect("admin/adminIndex.aspx");
}
else
{
Response.Write("
");
}
}
if(rblRole.SelectedValue =="2")
{
DataSet ds = StuBLL.GetList("stuNo = '"+ tbxUserName.Text.Trim() +"' and password = '"+ tbxPassword.Text.Trim() +"' and isDeleted = 0");
if(ds.Tables[0].Rows.Count == 1)
{
intid = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]);
Session["UserNo"] = ds.Tables[0].Rows[0]["id"];
Session["UserName"] = ds.Tables[0].Rows[0]["stuName"];
Response.Redirect("student/stusIndex.aspx");
}
else
{
Response.Write("
");
}
}
以stuWishChoices页面为例,继承PageBase类
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Data.SqlClient;
usingSystem.Collections;
namespacecbmis.ProDocumentMng
{
publicpartialclassDocumentList : BasePage//继承
{
protectedvoidPage_Load(objectsender, EventArgs e)
{
}
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10