這篇文章主要為大家詳細介紹了.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基礎影片教學
以上是.net實作後台登入驗證的詳細內容。更多資訊請關注PHP中文網其他相關文章!