DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Location
    Lackland AFB, TX
    Posts
    11

    Pull current user's email for support form

    Hello all,

    I am very green on asp.net. Learning as I go. What I am trying to do is create a helpdesk support from on our intranet that will send an email to our ticketing system that automatically generates a ticket. I have created a form, and it works, but the issue I am running into is that our ticketing system only recognizes a user's primary smtp address, or the mail attribute from LDAP. All others get thrown out. The form I created has an input field for email address. I already know that users will enter an incorrect email address. I would like for the form to automatically pull the user’s mail attribute from LDAP. The form will be on a intranet website with Anonymous access off and Integrated Windows authentication on. I have attached the files I currently have. Any help would be greatly appreciated.
    Attached Files
    Last edited by newbeee; 07-15-2010 at 08:18 PM.

  2. #2
    Join Date
    Oct 2008
    Posts
    141

    use system.directoryservices

    hi there,

    with that namespace, you will be able to retrieve emails from active directory (or other directory services you might have).

    look at this code, which is in this page http://forums.asp.net/t/1100757.aspx

    in c# is

    //-------------------------------------------
    DirectoryEntry entryRoot = new DirectoryEntry("LDAP://RootDSE");
    string domain = (string)entryRoot.Properties["defaultNamingContext"][0];
    string domainpath = "LDAP://" + domain;

    DirectoryEntry searchRoot = new DirectoryEntry(domainpath);
    DirectorySearcher search = new DirectorySearcher(searchRoot);
    search.Filter = "(&(objectClass=user)(objectCategory=person))";

    SearchResult result;
    search.PageSize = 1000;
    SearchResultCollection resultCol = search.FindAll();

    for (int counter = 0; counter < resultCol.Count; counter++)
    {
    result = resultCol[counter];
    result.Properties["givenName"][0];
    result.Properties["initials"][0];
    result.Properties["sn"][0];

    }
    //------------------------------------

    in vb.net, looks like it could be:

    '---------------------------------
    Dim rootEntry As New DirectoryEntry(ldapServerName, userID, Password)

    Dim searcher As New DirectorySearcher(rootEntry)

    searcher.PropertiesToLoad.Add("cn")

    searcher.PropertiesToLoad.Add("mail")

    'searcher.PropertiesToLoad.AddRange(New String() {"cn", "mail"})

    'would also work and saves you some code
    searcher.Filter =

    "(&(anr=jagjot)(objectCategory=person))"
    Dim results As SearchResultCollection
    results = searcher.FindAll()

    Dim result As SearchResult
    For Each result In results
    Me.eName.Text = result.Properties("cn")(0)
    Me.eMail.Text = result.GetDirectoryEntry.Properties.Item("mail").Value
    Me.eEmpNo.Text = result.GetDirectoryEntry.Properties.Item("employeeID").Value
    Me.ePhone.Text = result.GetDirectoryEntry.Properties.Item("telephoneNumber").Value
    Me.eLocation.Text = result.GetDirectoryEntry.Properties.Item("department").Value
    Me.eEtc.Text = result.GetDirectoryEntry.Properties.Item("PhysicalDeliveryOfficeName").Value
    Me.eTitle.Text = result.GetDirectoryEntry.Properties.Item("title").Value
    Next

    '--------------------------------------------------

    the vb.net example shows how to get email.
    other attributes found for an user in active directory are:

    [0]: "homemdb"
    [1]: "countrycode"
    [2]: "cn"
    [3]: "msexchuseraccountcontrol"
    [4]: "mailnickname"
    [5]: "msexchhomeservername"
    [6]: "msexchhidefromaddresslists"
    [7]: "msexchalobjectversion"
    [8]: "usncreated"
    [9]: "objectguid"
    [10]: "msexchrequireauthtosendto"
    [11]: "whenchanged"
    [12]: "memberof"
    [13]: "accountexpires"
    [14]: "displayname"
    [15]: "primarygroupid"
    [16]: "badpwdcount"
    [17]: "objectclass"
    [18]: "instancetype"
    [19]: "msmqdigests"
    [20]: "objectcategory"
    [21]: "samaccounttype"
    [22]: "whencreated"
    [23]: "lastlogon"
    [24]: "useraccountcontrol"
    [25]: "msmqsigncertificates"
    [26]: "samaccountname"
    [27]: "userparameters"
    [28]: "mail"
    [29]: "msexchmailboxsecuritydescriptor"
    [30]: "adspath"
    [31]: "lockouttime"
    [32]: "homemta"
    [33]: "description"
    [34]: "msexchmailboxguid"
    [35]: "pwdlastset"
    [36]: "logoncount"
    [37]: "codepage"
    [38]: "name"
    [39]: "usnchanged"
    [40]: "legacyexchangedn"
    [41]: "proxyaddresses"
    [42]: "userprincipalname"
    [43]: "admincount"
    [44]: "badpasswordtime"
    [45]: "objectsid"
    [46]: "msexchpoliciesincluded"
    [47]: "mdbusedefaults"
    [48]: "distinguishedname"
    [49]: "showinaddressbook"
    [50]: "givenname"
    [51]: "textencodedoraddress"
    [52]: "lastlogontimestamp"

    i ran queries with system.directoryservices and system.management for active directory and wmi back in 2003 and 2004. i pulled out ou's and groups from active directory, and the really hard part is coming out with ldap expression that goes in .filter property. if you prefer to use sql for active directory, you can use adsi, but it would be as a com object from dotnet.

    good luck,

    tonci.

  3. #3
    Join Date
    Jul 2004
    Location
    Lackland AFB, TX
    Posts
    11
    I will hive this a shot, thanks for the info

  4. #4
    Join Date
    Jul 2004
    Location
    Lackland AFB, TX
    Posts
    11
    well...I guess I am just too green to understand this....



    I'm not sure where this all goes.

Similar Threads

  1. Replies: 3
    Last Post: 08-09-2005, 12:59 PM
  2. Replies: 1
    Last Post: 11-26-2001, 12:28 AM
  3. Form Problem
    By ken in forum ASP.NET
    Replies: 1
    Last Post: 09-30-2000, 07:47 AM
  4. Check current users
    By Lia in forum ASP.NET
    Replies: 4
    Last Post: 08-09-2000, 02:13 PM
  5. Send email with another user's email ID.
    By nlw in forum Enterprise
    Replies: 1
    Last Post: 06-22-2000, 03:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links