C# 无法转换方法组';保存会话';非委托类型';对象';。您是否打算调用该方法?
每次登录时我都会遇到此错误:C# 无法转换方法组';保存会话';非委托类型';对象';。您是否打算调用该方法?,c#,asp.net,delegates,login-control,C#,Asp.net,Delegates,Login Control,每次登录时我都会遇到此错误: 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; b
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;
}
}
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()代码:
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;
}
}
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
。何时收到错误消息?调试时。SaveSession的代码从未执行过。听起来你好像忘记了方法上的括号,但我在上面的代码中看到了它们。有没有任何地方没有括号可以看到SaveSession
?我已经在上面呆了一个小时了。。。找不到出错的地方。调试器是否有显示此错误的特定代码行?