.net后台页面统一验证是否登录
本文实例为大家分享了.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,EventArgse)
{
if(Session["UserNo"]==null||Session["UserNo"].ToString()=="")
{
Response.Redirect("~/Login.aspx");
}
}
}
}
Login页面后台部分代码
protectedvoidbtnLogin_Click(objectsender,EventArgse)
{
if(rblRole.SelectedValue=="1")
{
DataSetds=AdminBLL.GetList("userName='"+tbxUserName.Text.Trim()+"'andpassword='"+tbxPassword.Text.Trim()+"'andisDeleted=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")
{
DataSetds=StuBLL.GetList("stuNo='"+tbxUserName.Text.Trim()+"'andpassword='"+tbxPassword.Text.Trim()+"'andisDeleted=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,EventArgse)
{
}
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。