asp.net登录不了
acto 2012-03-30 11:02:24 在adminsys文件夹里面,有个Default.aspx文件,是登录入口,输入用户名跟密码老是提示“用户名密码错误,登录失败”不知道什么问题,查看了数据库里面Admin表的用户名和密码,发现我输入的用户名跟密码都是没错的,请高手帮忙啊!
(1)/adminsys/Default.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Adminsys_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>后台登录</title>
<link href="../Adminsys/ML_style.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-image: none">
<form id="form1" runat="server">
<div style="text-align: center; margin-top: 100px;">
<table style="width: 424px; height: 293px;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 429px; height: 28px; background: url(images/we_1.gif); color: White;"
valign="bottom" align="left">
<strong> <asp:Label ID="lbl_Title" runat="server" Text=""></asp:Label>
</strong>
</td>
</tr>
<tr>
<td style="height: 126px; width: 429px;" align="center">
<asp:Image ID="adImg" runat="server" ImageUrl="images/we_2.gif" /></td>
</tr>
<tr>
<td style="height: 119; background: url(images/we_3.gif); width: 429px" align="center">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td valign="middle" style="width: 128px; height: 24px;" align="right">
<b>用户名:</b></td>
<td valign="middle" align="left">
<asp:TextBox ID="txt_username" runat="server" Style="border-right: #7b9fbe 1px solid;
border-top: #7b9fbe 1px solid; font-size: 12px; background: #f9f9f9; border-left: #7b9fbe 1px solid;
width: 120px; border-bottom: #7b9fbe 1px solid; height: 18px"></asp:TextBox>
<asp:RequiredFieldValidator ID="valrUserName" runat="server" ErrorMessage="请输入管理员用户名!"
ControlToValidate="txt_username"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="middle" align="right" style="height: 24px; width: 128px;">
<b>密 码:</b></td>
<td valign="middle" align="left">
<asp:TextBox ID="txt_pwd" runat="server" Style="border-right: #7b9fbe 1px solid;
border-top: #7b9fbe 1px solid; font-size: 12px; background: #f9f9f9; border-left: #7b9fbe 1px solid;
width: 120px; border-bottom: #7b9fbe 1px solid; height: 18px" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="valrPWD" runat="server" ControlToValidate="txt_pwd"
ErrorMessage="请输入管理员密码!"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="middle" align="right" style="height: 24px; width: 128px;">
<b>验证码:</b></td>
<td valign="middle" align="left">
<asp:TextBox ID="txt_ValidateNum" runat="server" Style="border-right: #7b9fbe 1px solid;
border-top: #7b9fbe 1px solid; font-size: 12px; background: #f9f9f9; border-left: #7b9fbe 1px solid;
width: 60px; border-bottom: #7b9fbe 1px solid; height: 18px"></asp:TextBox>
<asp:Image ID="ValidateNumber" runat="server" ImageUrl="~/Adminsys/chkcode/Image.aspx"
ImageAlign="AbsMiddle" />
<asp:RequiredFieldValidator ID="valrCode" runat="server" ControlToValidate="txt_ValidateNum"
ErrorMessage="请输入验证码!"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td valign="middle" colspan="2" align="center" style="height: 30px">
<asp:Button ID="btnSub" runat="server" Text=" 登 录 " OnClick="btnSub_Click" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 429px" align="center">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Adminsys/images/we_5.gif" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
(2)/adminsys/Default.aspx.cs文件(包含“登录”控件)代码如下:
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;
public partial class Adminsys_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lbl_Title.Text = Page.Title = Convert.ToString(Application["siteName"]) + "后台管理系统";
}
}
protected void btnSub_Click(object sender, EventArgs e)
{
string uname = txt_username.Text.ToString();
string pwd = txt_pwd.Text.ToString();
string validateNum = txt_ValidateNum.Text.ToString();
if (validateNum == (string)Session["CheckCode"])
{
string[] userInfo = admin.login(uname, pwd);
if (userInfo[2].Equals(pwd))
{
Session["userID"] = userInfo[0];
Session["userName"] = userInfo[1];
Session["pwd"] = userInfo[2];
Response.Redirect("admin_main.aspx");
}
else
{
Response.Write(jaylee.Msg("", "用户名密码错误,登录失败!"));
}
}
else
{
Response.Write(jaylee.Msg("", "验证码输入错误!"));
}
}
}