当前位置:编程学习 > C#/ASP.NET >>

在数据库中设定了用户名时 登录为什么不行 帮忙看一下

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;
using System.Data.OleDb;
public partial class main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "简易论坛—用户登录";
    }
    protected void ButtonEnter_Click(object sender, EventArgs e)
    {
        if (TextBoxName.Text == "" || TextBoxPassword.Text == "")
        {
            Response.Write("<script language=javascript>alert('用户名或密码不得为空!');</script>");
            return;
        }
        OleDbConnection conn = new OleDbConnection();
        conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" + "Data Source=" + Server.MapPath("App_Data/msg.mdb");
        conn.Open();//下面这两条语句是不是有问题 帮忙改一下
        string strSecPwd=FormsAuthentication.HashPasswordForStoringInConfigFile(TextBoxPassword.Text,"MD5");
        string strSQL="select ulevel from manager where uname='"+TextBoxName.Text+"'and upwd='"+strSecPwd+ "'";
        OleDbCommand com=new OleDbCommand(strSQL,conn);

        OleDbDataReader dr=com.ExecuteReader();
        dr.Read();
        string UserLevel;
        if(dr.HasRows)//在登录时 这语句就没执行 是怎么回事啊
            {
              UserLevel=dr["ulevel"].ToString();
              if (UserLevel == "0")
              {
                  Session["pass"] = "admin";
                  Response.Redirect("manager.aspx");
              }
              else
              {
                  Session["pass"] = "guest";
                  Response.Redirect("guest.aspx");
              }
            }
        else
            {
               Response.Write("<script language=javascript>alert('用户名或密码错误');</script>");
               return;
            }
            dr.Close();
            conn.Close();
        

    }
    protected void ButtonRegister_Click(object sender, EventArgs e)
    {
        Response.Redirect("register.aspx");
    }
}
--------------------编程问答-------------------- string strSecPwd=FormsAuthentication.HashPasswordForStoringInConfigFile(TextBoxPassword.Text,"MD5");
//输出strSecPwd值看看
  string strSQL="select ulevel from manager where uname='"+TextBoxName.Text+"'and upwd='"+strSecPwd+ "'";
//输出strSQL值,然后到查询分析器中执行下看看结果喽
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,