.net實現後台登入驗證

來源:互聯網
上載者:User
這篇文章主要為大家詳細介紹了.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('使用者名稱或密碼錯誤!')</script>");        }      }      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)        {          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('使用者名稱或密碼錯誤!')</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)      {          }    }  }}

【相關推薦】

1. ASP免費視頻教程

2. ASP教程

3. 李炎恢ASP基礎視頻教程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.