每次登录时我都会收到此错误:
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;
}
我错过了什么..? 我试图找到一个解决方案,但没有解决方案完全指向我的解决方案,我不在任何地方使用委托 - 这个错误来自哪里? 谢谢:))
答案 0 :(得分:0)
如果您没有在任何地方使用委托,您可能会看到此错误消息,因为您在SaveSession()
的方法调用之后省略了括号。看看你的代码,确保没有括号,SaveSession
没有括号。