index.aspx.cs

来自「简单新闻管理系统一个采用Access数据库的新闻管理系统」· CS 代码 · 共 76 行

CS
76
字号
using System;
using System.Data;
using System.Configuration;
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.OleDb;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {
            this.Label1.Text = "欢迎您!" + Session["username"];
        }
        else
        {

            this.Label1.Visible = false;
            this.LinkButton3.Visible = false;

        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("App_Data\\news.mdb");
            OleDbConnection conn = new OleDbConnection(strconn);
            string Username = "";
            string Pwd = "";
            Username = TextBox2.Text.Trim();
            Pwd = TextBox3.Text.Trim();
            string Sql;
            Sql = "select count(*) from userinfo where username='" + Username + "' and pwd='" + Pwd + "'";
            OleDbCommand cmd = new OleDbCommand(Sql, conn);
            conn.Open();
            int ret = (int)cmd.ExecuteScalar();
            conn.Close();
            if (ret <= 0)
            {

                Response.Write("<script> alert(\"登录失败!用户名或密码错误!\")</script>");


            }
            else
            {

                Session["username"] = Username;
               
                Response.Redirect("index.aspx");

                
            }
            





        }
    }
    
    protected void LinkButton3_Click1(object sender, EventArgs e)
    {

        Session["username"] = null;
        Response.Redirect("index.aspx");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?