我是一个全新的...
我正在尝试在 VS2010 中登录我的网站,该网站通过 asp.net 连接到现有的 SQL Server 2008 Express 数据库,使用 C# 作为背后的代码。
这是我的login.aspx.cs
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class Login : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnlogin_Click(object sender, EventArgs e)
{
int Results = 0;
if (txtUsername.Text != string.Empty && txtPassword.Text != string.Empty)
{
Results = Validate_Login(txtUsername.Text.Trim(), txtPassword.Text.Trim());
if (Results == 1)
{
lblMessage.Text = "Login is Good, Send user to another page or enable controls.";
}
else
{
lblMessage.Text = "Username or Password is incorrect.";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
else
{
lblMessage.Text = "Please make sure that your username and password is correct.";
}
}
protected int Validate_Login(String Username, String Password)
{
SqlConnection con = new SqlConnection(@"Server=MARIOM-PC\SQLEXPRESS;Database=Logon");
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandType = System.Data.CommandType.StoredProcedure;
cmdselect.CommandText = "[dbo].[prcLoginv]";
cmdselect.Parameters.Add("@Username", System.Data.SqlDbType.VarChar, 50).Value = Username;
cmdselect.Parameters.Add("@Password", System.Data.SqlDbType.VarChar, 50).Value = Password;
cmdselect.Parameters.Add("@OutRes", System.Data.SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = System.Data.ParameterDirection.Output;
cmdselect.Connection = con;
int Results = 0;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Results = (int)cmdselect.Parameters["@OutRes"].Value;
}
catch (SqlException ex)
{
lblMessage.Text = ex.Message;
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}
return Results;
}
}
当我单击我的登录按钮时,它会将我带到我的 C# 代码,在该代码后面应该遍历btn_Login_Click
,然后是Validate_Login
方法。但是它没有用正确的信息正确更新我的登录页面。我总是收到“密码错误”错误。
请帮忙!