Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 05, 2012 08:16 PM by spyxdaxworld
Member
431 Points
232 Posts
Jan 03, 2012 05:53 PM|LINK
I am getting red underline under "if (IsAuthenticated)". How can i fix it?
Below is the full code.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.DirectoryServices; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void btnLogin_Click(object sender, EventArgs e) { string DomainName = "ldap://11.12.202.38:389"; IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text); if (IsAuthenticated) { lblResult.Text = "login Success"; } else { lblResult.Text = "login failed"; } } public bool IsAuthenticated(String domain, String username, String pwd) { //Create the directory entry // Give LDAP Server IP along with OU // e.g : LDAP://29.29.29.29:389/DC=YourDomain,DC=com" string _path = "LDAP://11.12.202.38:389"; string _filterAttribute = ""; String domainAndUsername = domain + @"\" + username; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); bool returnval = true; string ErrDesc = ""; try { //Bind to the native AdsObject to force authentication. Object obj = entry.NativeObject; //Search the user on the Active Directory DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + username + ")"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if (null == result) { returnval = false; } //Update the new path to the user in the directory. _path = result.Path; _filterAttribute = (String)result.Properties["cn"][0]; } catch (Exception ex) { returnval = false; ErrDesc = "Error authenticating user. " + ex.Message; } return returnval; } } }
All-Star
112241 Points
18268 Posts
Moderator
Jan 03, 2012 05:57 PM|LINK
Jan 03, 2012 06:04 PM|LINK
i got this script off from some site. I am having trouble editing this script. Any idea what isauthenticated supposed to be?
Jan 03, 2012 06:09 PM|LINK
Jan 03, 2012 06:45 PM|LINK
I changed the
public bool IsAuthenticated(String domain, String username, String pwd) TO public bool IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text) Right next commas, there is red line displaying "Identifer expected"
Jan 03, 2012 06:48 PM|LINK
Jan 03, 2012 07:00 PM|LINK
I changed the IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text); TO bool IsAuthenticated = IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text); "IsAuthenticated" has red line,here is message for red line "(Local Variable) bool IsAuthenticated Error: 'IsAuthenticated' is a 'variable' but used like a 'method'
Jan 03, 2012 07:04 PM|LINK
Jan 03, 2012 07:16 PM|LINK
I changed the IsAuthenticated to isAuthenticated, I also changed on If statement. I get same error
Jan 03, 2012 07:19 PM|LINK
spyxdaxworld
Member
431 Points
232 Posts
Error on Line 19
Jan 03, 2012 05:53 PM|LINK
I am getting red underline under "if (IsAuthenticated)". How can i fix it?
Below is the full code.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.DirectoryServices; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void btnLogin_Click(object sender, EventArgs e) { string DomainName = "ldap://11.12.202.38:389"; IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text); if (IsAuthenticated) { lblResult.Text = "login Success"; } else { lblResult.Text = "login failed"; } } public bool IsAuthenticated(String domain, String username, String pwd) { //Create the directory entry // Give LDAP Server IP along with OU // e.g : LDAP://29.29.29.29:389/DC=YourDomain,DC=com" string _path = "LDAP://11.12.202.38:389"; string _filterAttribute = ""; String domainAndUsername = domain + @"\" + username; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); bool returnval = true; string ErrDesc = ""; try { //Bind to the native AdsObject to force authentication. Object obj = entry.NativeObject; //Search the user on the Active Directory DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + username + ")"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if (null == result) { returnval = false; } //Update the new path to the user in the directory. _path = result.Path; _filterAttribute = (String)result.Properties["cn"][0]; } catch (Exception ex) { returnval = false; ErrDesc = "Error authenticating user. " + ex.Message; } return returnval; } } }MetalAsp.Net
All-Star
112241 Points
18268 Posts
Moderator
Re: Error on Line 19
Jan 03, 2012 05:57 PM|LINK
spyxdaxworld
Member
431 Points
232 Posts
Re: Error on Line 19
Jan 03, 2012 06:04 PM|LINK
i got this script off from some site. I am having trouble editing this script. Any idea what isauthenticated supposed to be?
MetalAsp.Net
All-Star
112241 Points
18268 Posts
Moderator
Re: Error on Line 19
Jan 03, 2012 06:09 PM|LINK
spyxdaxworld
Member
431 Points
232 Posts
Re: Error on Line 19
Jan 03, 2012 06:45 PM|LINK
I changed the
public bool IsAuthenticated(String domain, String username, String pwd)
TO
public bool IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text)
Right next commas, there is red line displaying "Identifer expected"
MetalAsp.Net
All-Star
112241 Points
18268 Posts
Moderator
Re: Error on Line 19
Jan 03, 2012 06:48 PM|LINK
spyxdaxworld
Member
431 Points
232 Posts
Re: Error on Line 19
Jan 03, 2012 07:00 PM|LINK
I changed the
IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text);
TO
bool IsAuthenticated = IsAuthenticated(DomainName, TextBox1.Text, TextBox2.Text);
"IsAuthenticated" has red line,here is message for red line "(Local Variable) bool IsAuthenticated Error: 'IsAuthenticated' is a 'variable' but used like a 'method'
MetalAsp.Net
All-Star
112241 Points
18268 Posts
Moderator
Re: Error on Line 19
Jan 03, 2012 07:04 PM|LINK
spyxdaxworld
Member
431 Points
232 Posts
Re: Error on Line 19
Jan 03, 2012 07:16 PM|LINK
I changed the IsAuthenticated to isAuthenticated, I also changed on If statement. I get same error
MetalAsp.Net
All-Star
112241 Points
18268 Posts
Moderator
Re: Error on Line 19
Jan 03, 2012 07:19 PM|LINK