?? index.aspx.cs
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace book09
{
/// <summary>
/// Login 的摘要說明。
/// </summary>
public partial class Migrated_Login : Login
{
protected 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()
{
}
#endregion
protected 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";
string a = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.ToString(), "MD5");
cmd.Parameters.Add("@username",TextBox1.Text );
cmd.Parameters.Add("@password",a);
//存儲過程返回值
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(
TextBox1.Text, false);
Session["Username"] = TextBox1.Text;
}
else if (iRet == 1) //密碼不正確
{
Response.Write("<script>alert('密碼不正確')</script>");
}
else if (iRet == 2) //新注冊用戶
{
Response.Write("<script>alert('用戶不存在')</script>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -