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

ASP登陆界面问题,无法正常登陆

数据库库名为:ceshi2
      表名为:cs1
      列名: mc:tanxiang,password:123456;
第一前端default.aspx 代码为:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>用户登陆</title>
    <style type="text/css">
    .newStyle{
     font-family:宋体,Arial,Helvetica,sans-serif;font-size:24px;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" runat="server" Text="用户登陆" CssClass=" newStyle"></asp:Label>
        <br />
        <br />
    
        <asp:Label ID="label2" runat="server" Text="用户名:"></asp:Label>
        <asp:TextBox ID="txtuser" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="label3" runat="server" Text="密     码:"></asp:Label>
        <asp:TextBox ID="txtpass" runat="server"></asp:TextBox>
    
    </div>
   
    <asp:Button ID="Button1" runat="server" Text="登陆" />
    <asp:Button ID="Button2" runat="server" Text="重置" />
    </form>
</body>
</html>
第二连接数据库web.config主要代码为:
</configSections>
<appSettings>
<add key="sqlconn" value="server=SERVER\SQL2005;database=ceshi2;uid=sa;pwd=123456"/>
</appSettings>
<connectionStrings/>

三,default.aspx.cs代码为:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string mc = BS201102.DSQL.GetDataFieldBySearch("select mc from cs1");
        BS201102.Other.MyControl.Alerts(mc);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String name = txtuser.Text;
        String pass = txtpass.Text;
        string WelStr = "欢迎你来到会员中,现在时间是:" + DateTime.Now.ToString();
        string ErrorStr = "<font color=red>对不起,你的信息不正确,请重试!</font>";
        if (Test.isLogin(name, pass))
        {
            Response.Write(WelStr);
        }

        else {
            Response.Write(ErrorStr);
        }
    }


            protected void Button2_Click(object sender, Exception e)
    {
        txtuser.Text = "";
        txtpass.Text = "";
    }
    }
第四,类代码为:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
///Test 的摘要说明
/// </summary>
public class Test
{
    public static bool isLogin(string u, string p)
    {
        u = u.Trim();
        p = p.Trim();
        if (u.Equals("zht") && p.Equals("itZcn"))
        {
            return true;
        }
        return false;
    }

}
--------------------编程问答-------------------- 什么叫无法正常登陆..
异常提示是什么. --------------------编程问答-------------------- 一无法显示时间,
二只显示失败的页面,不能成功登陆 --------------------编程问答-------------------- 你用这个用户名和密码登录就可以进了:
zht
itZcn

你的代码把用户名和密码固定死了,没有从数据库中获取要对比的帐号。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,