ホームページ  >  記事  >  バックエンド開発  >  .netはバックグラウンドログイン検証を実装します

.netはバックグラウンドログイン検証を実装します

Y2J
Y2Jオリジナル
2017-05-12 10:15:591311ブラウズ

この記事では、主に .net バックエンド ページでのログインの統合認証方法を詳しく紹介します。興味のある方は参考にしてください。

この記事の例は、.net の統合認証を皆さんと共有します。ログインするかどうかの具体的なコードは次のとおりです

まず、新しい 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");
      }
    }
  }
}

ログイン ページの背景部分のコード

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(&#39;用户名或密码错误!&#39;)</script>");
        }
      }
      if (rblRole.SelectedValue == "2")
      {
        DataSet ds = StuBLL.GetList("stuNo = &#39;" + tbxUserName.Text.Trim() + "&#39; and password = &#39;" + tbxPassword.Text.Trim() + "&#39; 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(&#39;用户名或密码错误!&#39;)</script>");
        }
      }

stuWishChoices ページを例に挙げます。 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)
      {
    
      }

    }
  }
}

[関連する推奨事項]

1.

ASP チュートリアル

3.

Li Yanhui ASP 基本ビデオ チュートリアル

以上が.netはバックグラウンドログイン検証を実装しますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。