當前位置:編程學習大全網 - 源碼下載 - 求web中的asp.net程序題login.aspx用於網站的登錄驗證的程序

求web中的asp.net程序題login.aspx用於網站的登錄驗證的程序

1、登錄頁login.aspx代碼:

using?System;

using?System.Collections.Generic;

using?System.Linq;

using?System.Web;

using?System.Web.UI;

using?System.Web.UI.WebControls;

namespace?wgxt.Controllers

{

public?partial?class?login?:?System.Web.UI.Page

{

protected?void?Page_Load(object?sender,?EventArgs?e)

{

}

protected?void?Button1_Click(object?sender,?EventArgs?e)

{

string?username?=?TextBox1.Text;//獲取輸入的用戶名稱

string?password?=?TextBox2.Text;//獲取輸入的用戶密碼

if?(username=="admin"?&&?password=="123456")

{

Session["islogin"]?=?"login";//記錄登錄成功

Response.Redirect("WebForm1.aspx");//登錄成功後跳轉到webform1.aspx頁

}

else

{

Response.Write("<script>alert('用戶名和密碼輸入不匹配,請重輸!');</script>");

}

}

}

}

2、WebForm1.aspx頁代碼

using?System;

using?System.Collections.Generic;

using?System.Linq;

using?System.Web;

using?System.Web.UI;

using?System.Web.UI.WebControls;

namespace?wgxt.Controllers

{

public?partial?class?WebForm1?:?System.Web.UI.Page

{

protected?void?Page_Load(object?sender,?EventArgs?e)

{

if?(Session["islogin"]?==null?||?Session["islogin"].ToString()?==?"")//判斷是否登錄

{

Response.Redirect("login.aspx");//沒有登錄驗證跳轉回重新登錄

}

}

}

}

  • 上一篇:Mpp源代碼
  • 下一篇:說說在 Android 中如何發送 HTTP 請求
  • copyright 2024編程學習大全網