?? index.aspx.cs
字號(hào):
using System;
using System.Collections;
using System.ComponentModel;
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;
//該源碼下載自www.51aspx.com(51aspx.com)namespace examonline
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁(yè)面
}
#region Web 窗體設(shè)計(jì)器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
private void login()
{
string mpsw = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtpsw.Text, "MD5");
string sql = "select * from [admin] where username='" + txtid.Text.Trim() + "' and password='" + mpsw + "'";
SqlConnection cn = new SqlConnection("server=(local);uid=sa;pwd=51aspx;database=examonline");
SqlCommand cmd = new SqlCommand(sql, cn);
SqlDataReader dr;
try
{
cn.Open();
dr = cmd.ExecuteReader();
if(dr.Read())
{
Session["UserID"] = dr.GetValue(0);
Session["UserName"] = dr.GetString(1);
Session["IsLogined"] = true;
Response.Redirect("showexam.aspx");
}
else
{
lblmsg.Text = "用戶名或密碼錯(cuò)誤!";
}
}
catch(SqlException ex)
{
lblmsg.Text = "數(shù)據(jù)庫(kù)錯(cuò)誤:" + ex.Message.ToString();
}
finally
{
cn.Close();
}
}
protected void btnlogin_Click(System.Object sender, System.EventArgs e)
{
if(txtcode.Text ==(string)Session["vali"])
{
login();
}
else
{
lblmsg.Text = "所填寫的驗(yàn)證碼與所給的不符!";
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -