本文实例为大家分享了.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)
{
}
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助
地铁逃生官方正版极速下载入口安卓-Pubg地铁逃生2026最新直装版官网免费下载
邵氏经典电影夸克分享-香港邵氏50部经典电影无码未删减资源在线看
可可漫画官网客户端下载安装最新版本入口怎么进-可可漫画官网安卓苹果下载直达
罚罪1+2最新一集未删减在线看-罚罪1+2全80集蓝光高清1080p无删减资源夸克免费观看入口
罚罪1+280集高清完整版迅雷云盘下载1080P(4k)资源
杨紫《生命树》全集高清1080P/4K阿里云盘资源下载无删减