0

I am working on an C# and ASP.Net application, that uses Forms Authentication that I found here... http://msdn.microsoft.com/en-us/library/ms180890(v=vs.90).aspx

It works great but now I would like to go alittle further and also pull the email address from the mail field in LDAP and pipe it to a text with the rest of the

lblName.Text = "Hello " + Context.User.Identity.Name + ".";
  lblAuthType.Text = "You were authenticated using " 
                     + Context.User.Identity.AuthenticationType + ".";

I searched and read theses links looking for an answer...

How to get the current user's Active Directory details in C#

How to use email as httpcontext.User.Identity.name

http://www.codekeep.net/snippets/402e4677-f8d0-419c-b656-b3c28e740296.aspx

from what I can tell I need to add code to the LdapAuthentication.cs like another DirectorySearcher query but do I have to make a totally new search or can I just add it to the query it makes when it looks up the usersname?? Like

            DirectorySearcher search = new DirectorySearcher(entry);

            search.Filter = "(SAMAccountName=" + username + ")";
            search.PropertiesToLoad.Add("cn");
            search.PropertiesToLoad.Add("mail");  // e-mail address
            SearchResult result = search.FindOne();

            if (null == result)
            {
                return false;
            }

..I'm so new to this and I'm trying so hard but I can't get this.. any help?

Community
  • 1
  • 1
Red Tide
  • 1
  • 1
  • 1

2 Answers2

0

You can add mail to the PropertiesToLoad and then you can get the result by accessing (String)result.Properties["mail"][0]. Properties is a 2d array, with the first vector being the attribute name, and the second is used in case the attribute is multivariable.

Kodra
  • 1,576
  • 1
  • 10
  • 6
0

You should see Implementing a Profile Provider and ASP.NET Profile Properties Overview on MSDN. Implementing a ProfileProvider makes properties available through the Profile object. That way, you can provide whatever additional information you want.

JamieSee
  • 12,696
  • 2
  • 31
  • 47