.net后臺頁面統(tǒng)一驗(yàn)證是否登錄
本文實(shí)例為大家分享了.net后臺頁面統(tǒng)一驗(yàn)證是否登錄的具體代碼,供大家參考,具體內(nèi)容如下
首先新寫一個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) { } } } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
asp.net中IDataParameter調(diào)用存儲過程的實(shí)現(xiàn)方法
這篇文章主要介紹了asp.net中IDataParameter調(diào)用存儲過程的實(shí)現(xiàn)方法,在asp.net數(shù)據(jù)庫程序設(shè)計(jì)中非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-09-09asp.net中獲取遠(yuǎn)程網(wǎng)頁的內(nèi)容之一(downmoon原創(chuàng))
asp.net中獲取遠(yuǎn)程網(wǎng)頁的內(nèi)容之一(downmoon原創(chuàng))...2007-04-04ASP.NET Core學(xué)習(xí)之使用JWT認(rèn)證授權(quán)詳解
這篇文章主要給大家介紹了關(guān)于ASP.NET Core學(xué)習(xí)之使用JWT認(rèn)證授權(quán)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用ASP.NET Core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08asp.net SqlParameter如何根據(jù)條件有選擇的添加參數(shù)
有時(shí)候?qū)憇ql語句的時(shí)候會根據(jù)方法傳進(jìn)來的參數(shù)來判斷sql語句中where條件的參數(shù),下面有個示例,大家可以參考下2014-06-06