?? admin_login.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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.Data.SqlClient;
using System.Configuration;
namespace WebNews.admin
{
/// <summary>
/// admin_login 的摘要說明。
/// </summary>
public class admin_login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox Username;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.Button Submit;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
if(!Page.IsPostBack)
{
Session["userclass"]="";
Session["pwd"]="" ;
Session["classname"]="";
Session["username"]="";
}
}
private void conn(string t1,string t2) //驗證過程
{
try
{
string con=ConfigurationSettings.AppSettings["dsn"]; //取得DSN字符
SqlConnection myConnection = new SqlConnection(con);//連接字符串
myConnection.Open(); //連接數據庫
SqlCommand cd=new SqlCommand("sp_selAdmin",myConnection); //設置SQL命令
cd.CommandType=CommandType.StoredProcedure; //調用存儲過程
SqlParameter username= cd.Parameters.Add("@username", SqlDbType.Char,240); //設置存儲過程參數
SqlParameter password= cd.Parameters.Add("@password", SqlDbType.NChar,240);
username.Value=t1;
password.Value=t2;
SqlDataReader selreader ; //設置SqlDataReader 類
selreader=cd.ExecuteReader(); //命令執行
if (selreader.Read()==true) //驗證
{
Session["userclass"]=selreader.GetString(3);
string popedom=selreader.GetString(6); //驗證是否有增加新聞的功能
Session["userclass"]=selreader.GetString(3);
Session["classname"]=selreader.GetString(7);
Session["popedom"]=selreader.GetString(6);
Session["pwd"]=selreader.GetString(2);
Session["id"]=selreader.GetInt64(0);
Session["power"]=selreader.GetString(6);
int i=popedom.Length;
string df=popedom.Replace("addnews","1");
Session["popedom"]=df;
int j=df.Length;
if(i!=j)
{
Session["addnews"]=1;
}
else Session["addnews"]=0;
i=popedom.Length; //驗證是否有增加新聞不需審核功能的權限
df=popedom.Replace("addnchk","1");
j=df.Length ;
if(i!=j)
{
Session["addnchk"]=1;
}
else Session["addnchk"]=0;
i=popedom.Length; //驗證是否有修改新聞的權限
df=popedom.Replace("chgnews","1");
j=df.Length ;
if(i!=j)
{
Session["chgnews"]=1;
}
else Session["chgnews"]=0;
i=popedom.Length; //驗證是否有審核新聞的權限
df=popedom.Replace("chknews","1");
j=df.Length ;
if(i!=j)
{
Session["chknews"]=1;
}
else Session["chknews"]=0;
i=popedom.Length; //驗證是否有管理評論的權限
df=popedom.Replace("remark","1");
j=df.Length ;
if(i!=j)
{
Session["remark"]=1;
}
else Session["remark"]=0;
selreader.Close(); //關閉連接
myConnection.Close();
Response.Redirect("admin_main.htm"); //轉向admin_main.htm
}
else
{
selreader.Close(); //關閉連接
myConnection.Close();
Label1.Text="用戶名或密碼錯誤";
}
}
catch(SqlException e)
{
Console.WriteLine("Exception in Main: " + e.Message); //出錯處理
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Submit.Click += new System.EventHandler(this.Submit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Submit_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
string username=Request["Username"]; //用戶名
string password=Request["Password"]; //密碼
Session["username"]=username;
conn(username,password); //驗證用戶密碼
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -