我正在尝试在 Xamarin 中创建针对 LDAP 的身份验证。我有 Main.xaml,我在其中创建了带有按钮的简单登录表单(Entry Placeholder="*Password" IsPassword="True" x:Name="login_password")(Button Clicked ="btnLogin_Clicked" Text="Sign in" x:Name ="btn登录")。Main.xaml.cs 包含 LDAP 连接的代码。我在那里检查凭据并尝试绑定。
不幸的是,我收到此错误:“在类型‘Main.xaml’中找不到具有正确签名的事件处理程序‘btnLogin_Clicked’”。
我花了很多时间在这上面,但仍然不明白我做错了什么。如果有人可以帮助我或给我一些关于在哪里可以搜索答案的建议,我将不胜感激。
我的一段代码:
public void btnLogin_Clicked(object sender,string login_username, string login_password, System.EventArgs e)
{
string searchBase = "dc = it, dc = local";
string searchFilter = "(amemberOf=ALL)";
string ldapHost = "7777.. ";
int ldapPort = 389;
string loginDN = "dc = it, dc = local";
/*if username or passworwd fields are empty show an error*/
if (login_username is null || login_password is null)
{
DisplayAlert("Alert", "Please, enter your credentials", "OK");
}
else
{
/*creating an LDAP instance*/
using (LdapConnection connection = new LdapConnection())
/*here we create new ldap connection*/
try
{
/*connect function will creat socket connection to the server*/
connection.Connect(ldapHost, ldapPort);
connection.Bind(string.Format("{0}@{1}", loginDN, login_username), login_password);
LdapSearchQueue queue = connection.Search(searchBase,
LdapConnection.SCOPE_ONE, searchFilter, null, false, (LdapSearchQueue)
null, (LdapSearchConstraints)null);
LdapMessage message;
while ((message = queue.getResponse()) != null)
{
if (message is LdapSearchResult)
{
/*display message if connect*/
DisplayAlert("" ," logged in ", "OK ");
}
else
{
/*if the message is not null but the login was failed*/
DisplayAlert("", "Login failed", "OK ");
}...
Run Code Online (Sandbox Code Playgroud)
Jas*_*son 11
按钮的事件处理程序具有签名
public void btnLogin_Clicked(object sender, System.EventArgs e)
Run Code Online (Sandbox Code Playgroud)
您不能只向签名添加额外的参数