[英]ASP.NET MVC MySQL Access denied for user 'root'@'localhost' (using password: NO)
[英]User/Password Verification using ASP.NET against a MySQL database
強文本
protected void btnLogin_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["moverschoiceConnectionString"].ConnectionString;
OdbcConnection conn = new OdbcConnection(connectionString);
conn.Open();
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = conn;
cmd.CommandText = "select Email, Password from brokercenter where Email = '" + txtLoginEmail.Text + "'";
OdbcDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
if (reader["Password"].ToString() == txtLoginPassword.Text)
{
reader.Close();
Response.Redirect("BrokerResources.aspx");
}
else
{
lblLoginError.Text = "Invalid Password";
}
}
else
{
lblLoginError.Text = "Invalid Email Address";
}
}
請理解,我剛剛完成入門級C#的學習,並被該公司聘請來開發站點。 以前的.NET家伙剛剛離開,所以我不知道他在哪里做什么。 這是我在此站點上的第一個問題,因此,如果格式不正確,我深表歉意。 我對此並不陌生,可以使用任何幫助。 簡而言之,我有兩個文本框和一個按鈕。 我可以讓用戶創建一個帳戶,該帳戶進入dB,但是我無法獲得要驗證的電子郵件(用戶名)和密碼。 當我單擊按鈕時,什么也沒有發生。 該公司有許多站點,因此我試圖從另一個登錄按鈕進行復制和粘貼,並更改我需要匹配當前站點信息的內容,但沒有進行任何更改。 我檢查了大約兩天,並嘗試了許多版本的登錄代碼,但仍然沒有。 我不知道此系統上已經安裝了什么。 同樣,我是入門級的(實際上是在10號剛完成的課程),所以請使用小寫單詞。
提前致謝!
單擊按鈕后,應觸發btnLogin_Click()
。 在btnLogin_Click
之后,您應該重定向到另一個頁面Response.Redirect
或對用戶lblLoginError.Text =
的反饋。
如果沒有任何反應,我想btnLogin_Click()
未鏈接到按鈕:在aspx頁面上,您應該具有<asp:Button ID="btnLogin" runat="server" onclick="btnLogin_Click" ..>
無論如何,在btnLogin_Click()
內的任何地方放置一個斷點,開始調試並查看是否觸發!
試試這個代碼可以解決你的問題
protected void btnLogin_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["moverschoiceConnectionString"].ConnectionString;
OdbcConnection conn = new OdbcConnection(connectionString);
conn.Open();
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = conn;
cmd.CommandText = "select Email, Password from brokercenter where Email = '" + txtLoginEmail.Text + "'";
OdbcDataReader reader = cmd.ExecuteReader();
While(reader.Read())
{
if (reader["Password"].ToString() == txtLoginPassword.Text)
{
reader.Close();
Response.Redirect("BrokerResources.aspx");
}
else
{
lblLoginError.Text = "Invalid Password";
}
}
lblLoginError.Text = "Invalid Email Address";
reader.Close();
}
由於您是新手,所以我想幫助您了解有關此代碼的一些知識。 我將概述代碼的功能:
另外,正如已經提到的那樣,檢查Asp.net腳本中的按鈕單擊事件,方法名稱需要與頁面本身上指定的名稱匹配以進行連接。
希望這可以為您提供一些工作,並希望它將指導您的學習。
祝一切順利
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.