The. net background page verifies whether to log on and the. net background page.
The examples in this article share with you the specific code of the. net background page for unified verification of logon, for your reference. The specific content is as follows:
First, write a new PageBase class.
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"); } } }}
Some background code of the Login page
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"] = d S. tables [0]. rows [0] ["userName"]; Response. redirect ("admin/adminIndex. aspx ");} else {Response. write ("<script> alert ('user name or password is incorrect! ') </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. red Irect ("student/stusIndex. aspx");} else {Response. Write ("<script> alert ('user name or Password error! ') </Script> ");}}
Take the stuWishChoices page as an example to inherit the PageBase class
Using System. web. UI. webControls. webParts; using System. data. sqlClient; using System. collections; namespace cbmis. proDocumentMng {public partial class DocumentList: BasePage // inherit {protected void Page_Load (object sender, EventArgs e ){}}}}
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.