首頁  >  文章  >  後端開發  >  .net驗證後台頁面是否登入實例教學

.net驗證後台頁面是否登入實例教學

巴扎黑
巴扎黑原創
2017-08-14 13:29:131837瀏覽

這篇文章主要為大家詳細介紹了.net後台頁面統一驗證是否登入的方法,具有一定的參考價值,有興趣的小夥伴們可以參考一下

本文實例為大家分享了.net後台頁面統一驗證是否登入的具體程式碼,供大家參考,具體內容如下

首先新寫一個PageBase類別


#
using System;
using System.Collections.Generic;
using System.Web;

namespace DepartmentMIS.Web.myclass
{
  public class PageBase : System.Web.UI.Page
  {
    public PageBase()
    {
      this.Load += new EventHandler(BasePage_Load);
    }

    private void BasePage_Load(object sender, EventArgs e)
    {
      if (Session["UserNo"] == null || Session["UserNo"].ToString() == "")
      {
        Response.Redirect("~/Login.aspx");
      }
    }
  }
}

Login頁面後台部分程式碼


protected void btnLogin_Click(object sender, 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)
        {
          int id = 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("<script>alert(&#39;用户名或密码错误!&#39;)</script>");
        }
      }
      if (rblRole.SelectedValue == "2")
      {
        DataSet ds = StuBLL.GetList("stuNo = &#39;" + tbxUserName.Text.Trim() + "&#39; and password = &#39;" + tbxPassword.Text.Trim() + "&#39; and isDeleted = 0");
        if (ds.Tables[0].Rows.Count == 1)
        {
          int id = 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("<script>alert(&#39;用户名或密码错误!&#39;)</script>");
        }
      }

以stuWishChoices頁面為例,繼承PageBase類別


using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Collections;

namespace cbmis.ProDocumentMng
{
  public partial class DocumentList : BasePage //继承
  {
      protected void Page_Load(object sender, EventArgs e)
      {
    
      }

    }
  }
}

以上是.net驗證後台頁面是否登入實例教學的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn