I am currently studying asp.net programs and I have mastered the concepts well. But however , I am not able to solve this issue . can you sort out for me. I am with an error on line 19 and I am getting red underline under "if (IsAuthenticated)". I will provide with the entire code along this one. So can you guys solve it for me.
Code:
using System;
using System.Net;
using System.DirectoryServices;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SSS23
{
public partial class _Default : System.Web.UI.Page
{
protected void btnLogin_Click(object user , EventArgs e)
{
string DomainName = "ldap://14.67.804.45:624";
IsAuthenticated(DomainName, TextBox3.Text, TextBox5.Text);
if (IsAuthenticated)
{
lblResult.Text = "login Success";
}
else
{
lblResult.Text = "login failed";
}
}
public bool IsAuthenticated(String domain, String username, String pwd)
{
string _path = "LDAP:// 14.67.804.45:624";
string _filterAttribute = "";
String domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
bool returnval = true;
string ErrDesc = "";
try
{
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(sssAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
returnval = false;
}
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
returnval = false;
ErrDesc = "Error authenticating user. " + ex.Message;
}
return returnval;
}
}
}
Bookmarks