|
发表于 2020-11-27 13:00:01
|
显示全部楼层
登陆页
using System;
using System.Data;
using System.Data.SqlClient;
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;
public partial class admin_index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Title = "后台登陆";
}
protected void dl_Click(object sender, EventArgs e)
{
string admin_name = Request["l_name"].ToString();
string admin_pwd = Request["l_pwd"].ToString();
string connstring = System.Configuration.ConfigurationManager.AppSettings["myconn"];
SqlConnection thisconnection = new SqlConnection(connstring);
string sql = "select * from admin where admin_name ='"+admin_name+"' and admin_pwd = '"+admin_pwd+"'";
SqlCommand thiscommand = new SqlCommand(sql,thisconnection);
thiscommand.CommandType = CommandType.Text;
try
{
thiscommand.Connection.Open();
SqlDataReader dr = thiscommand.ExecuteReader();
if (dr.Read())
{
Session["admin_name"] = admin_name;
Response.Redirect("class.aspx");
}
else
{
this.l_error.Text = "用户名或者密码错误";
}
}
catch (SqlException ex)
{
Response.Write(ex.ToString());
}
finally
{
thiscommand.Connection.Close();
}
}
}
其他页都加上
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin_name"] == null)
{
Response.Redirect("index.aspx");
}
} |
|