【发布时间】:2017-06-23 22:50:09
【问题描述】:
每次登录时我都会收到此错误:
Cannot convert method group 'Save Session' to non-delegate type 'object'. Did you intend to invoke the method?
这是我的 Login1 组件代码:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
Boolean blnresult;
blnresult = false;
// Pass UserName and Password from login1 control to an authentication function which will check will check the user name and password from sql server.
// Then will retrun a true or false value into blnresult variable
blnresult = Authentication(Login1.UserName, Login1.Password);
// If blnresult has a true value then authenticate user
if (blnresult == true)
{
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
SaveSession();
// This is the actual statement which will authenticate the user
e.Authenticated = true;
}
else
{ // If user faild to provide valid user name and password
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Materialize.toast('הפרטים שהוקשו שגויים.', 4000);", true);
e.Authenticated = false;
}
}
SaveSession() 代码:
protected void SaveSession()
{
var connn = new MySqlConnection(ConfigurationManager.ConnectionStrings["Db"].ConnectionString);
// Save SessionID in db
string querySession = "UPDATE Users SET SessionID = @SessionID WHERE Id = @Id";
MySqlCommand cmdSession = new MySqlCommand(querySession.Replace("'", ""), connn);
cmdSession.Parameters.AddWithValue("@SessionID", Session.SessionID);
cmdSession.Parameters.AddWithValue("@Id", GetUserId(Login1.UserName, Login1.Password));
GlobalFunctions.CheckCon();
try
{
connn.Open();
cmdSession.ExecuteNonQuery();
}
catch { }
finally
{
connn.Close();
}
GlobalFunctions.getUserid(GetUserId(Login1.UserName, Login1.Password));
GlobalFunctions.logged = true;
}
我错过了什么..? 我试图在那里找到一个解决方案,但没有解决方案完全指向我的解决方案,我不在任何地方使用委托 - 这个错误来自哪里? 谢谢:)
【问题讨论】:
-
什么时候收到错误信息?
-
调试时。 SaveSession 的代码永远不会被执行。
-
听起来您忘记了方法上的括号,但我在上面的代码中看到了它们。有没有看到
SaveSession不带括号的地方? -
我已经做了一个小时了...找不到问题所在。
-
调试器是否有任何特定的代码行显示此错误?
标签: c# asp.net delegates login-control