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

