一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

.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)

      {

      

      }

  

    }

  }

}

以上就是本文的全部内容,希望对大家的学习有所帮助

热门栏目