The. net background page verifies whether to log on and the. net background page.

Source: Internet
Author: User

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.

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.