This article is mainly for you to introduce in detail the. NET Background page Unified authentication method, with a certain reference value, interested in small partners can refer to
The example of this article for everyone to share the. NET Background page Unified authentication is the specific code, for everyone to refer to, 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") ; } }}
Login Page Background Part code
protected void Btnlogin_click (object sender, EventArgs e) {if (Rblrole.selectedvalue = = "1") {Datase T ds = adminbll.getlist ("UserName = '" + TbxUserName.Text.Trim () + "' and password = '" + TbxPassword.Text.Trim () + "' And I sdeleted = 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 (' username or password is wrong! ') </script> "); }} if (Rblrole.selectedvalue = = "2") {DataSet ds = stubll.getlist ("Stuno = '" + tbxusername.text.t Rim () + "' 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 (' username or password is wrong! ') </script> "); } }
Take Stuwishchoices page For example, Inherit Pagebase class
Using system.web.ui.webcontrols.webparts;using system.data.sqlclient;using system.collections;namespace cbmis. prodocumentmng{public Partial class Documentlist:basepage//Inheritance { protected void Page_Load (object sender, EventArgs e) { } } }}
"Recommended"
1. asp free Video Tutorial
2. asp Tutorials
3. Eon the ASP Basic video tutorial