.net后臺頁面統(tǒng)一驗證是否登錄
更新時間:2017年04月25日 09:35:46 作者:真果粒
這篇文章主要為大家詳細介紹了.net后臺頁面統(tǒng)一驗證是否登錄的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了.net后臺頁面統(tǒng)一驗證是否登錄的具體代碼,供大家參考,具體內(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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
asp.net中IDataParameter調(diào)用存儲過程的實現(xiàn)方法
這篇文章主要介紹了asp.net中IDataParameter調(diào)用存儲過程的實現(xiàn)方法,在asp.net數(shù)據(jù)庫程序設計中非常具有實用價值,需要的朋友可以參考下2014-09-09asp.net中獲取遠程網(wǎng)頁的內(nèi)容之一(downmoon原創(chuàng))
asp.net中獲取遠程網(wǎng)頁的內(nèi)容之一(downmoon原創(chuàng))...2007-04-04asp.net SqlParameter如何根據(jù)條件有選擇的添加參數(shù)
有時候寫sql語句的時候會根據(jù)方法傳進來的參數(shù)來判斷sql語句中where條件的參數(shù),下面有個示例,大家可以參考下2014-06-06