?? login.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
namespace book09
{
/// <summary>
/// Login 的摘要說明。
/// </summary>
public class Login : System.Web.UI.Page
{
protected book09.LoginCustomControl LoginCustomControl1;
protected System.Web.UI.WebControls.Label lblMessage;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.LoginCustomControl1.Login += new System.EventHandler(this.LoginCustomControl1_Login);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LoginCustomControl1_Login(object sender, System.EventArgs e)
{
int iRet = -1;
SqlConnection conn = new SqlConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "UserLogin";
cmd.Parameters.Add("@username", LoginCustomControl1.UserName);
cmd.Parameters.Add("@password", LoginCustomControl1.Password);
//存儲過程返回值
SqlParameter paramOut = cmd.Parameters.Add("@RETURN_VALUE", "");
paramOut.Direction = ParameterDirection.ReturnValue;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
iRet = (int)cmd.Parameters["@RETURN_VALUE"].Value;
if (iRet == 0) //登錄成功
{
FormsAuthentication.RedirectFromLoginPage(
LoginCustomControl1.UserName, false);
}
else if (iRet == 1) //密碼不正確
{
Response.Write("<script>alert('密碼不正確')</script>");
}
else if (iRet == 2) //新注冊用戶
{
FormsAuthentication.RedirectFromLoginPage(
LoginCustomControl1.UserName, false);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -