getting red underline under "if (IsAuthenticated)" Error on Line 19 in asp.net program.
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;
}
}
}
Re: getting red underline under "if (IsAuthenticated)" Error on Line 19 in asp.net program.
As you are more concerned with the authentication part, I need to say that you need to provide with me that what is isauthenticated supposed to be? I am not able to see a property or else variable with the similar name. I am able to see an isauthenticated method. So can you specify further in this case.
Re: getting red underline under "if (IsAuthenticated)" Error on Line 19 in asp.net program.
I have found this error and you can try with this one. You need to change the line by bool IsAuthenticated = IsAuthenticated(DomainName, TextBox3.Text, TextBox5.Text); and it will eb solved. It will take a bool value and you need to specify the domain name .
Re: getting red underline under "if (IsAuthenticated)" Error on Line 19 in asp.net program.
I made some changes and it was solved in my case. I made some changes in the
public bool IsAuthenticated(String domain, String username, String pwd)
TO
public bool IsAuthenticated(DomainName, TextBox3.Text, TextBox5.Text)
and it was solved. You can attempt this one and then reply for the same.
Re: getting red underline under "if (IsAuthenticated)" Error on Line 19 in asp.net program.
I need to say that we are definite that there are some errors or you will be having some variable name issues and I have attempted in this case and after making the below change you will have a correct result.
Code:
bool result = IsAuthenticated(DomainName, TextBox3.Text, TextBox5.Text);
if (result)
{
lblResult.Text = "login Success";
}
else
{
lblResult.Text = "login failed";
}
Re: getting red underline under "if (IsAuthenticated)" Error on Line 19 in asp.net program.
Thanks for the replies and it was solved I made some changes and after this one everything was sorted out. "DirectorySearcher search = new DirectorySearcher(entry);" and after putting an breakpoint , it was solved in my case.