. NET For background login verification

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.