Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

asp.net c# get user email address from AD

using System.Linq;
using System.DirectoryServices;

string username = User.Identity.Name.Split('').Last();
string email = GetMail(username);

static string GetMail(string user)
{
  using (var connection = new DirectoryEntry())
  {
    using (var search = new DirectorySearcher(connection)
      {
        Filter = "(samaccountname=" + user + ")",
        PropertiesToLoad = {"mail"},
      })
    {
      return (string) search.FindOne().Properties["mail"][0];
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# lambda group by multiple columns 
Csharp :: How to install a windows service programmatically in C#? 
Csharp :: unity get distance between line and point 
Csharp :: c# code to check anagram 
Csharp :: unity array c# 
Csharp :: c# draggable controls 
Csharp :: query associative table ef6 
Csharp :: KeyValuePair is default 
Csharp :: remove substring from string c# 
Csharp :: C# get filebase name 
Csharp :: Get logged in user in ASP.Net 
Csharp :: how to count letters in c# 
Csharp :: select a whole row out of a 2d array C# 
Csharp :: C# random multiple of 5 in range 
Csharp :: mysql restore backup from multiple files 
Csharp :: c# async and await example 
Csharp :: convert rgb to float 
Csharp :: ef core many to many fluent api 
Csharp :: c# for loops 
Csharp :: c# method 
Csharp :: c# return multiple values 
Csharp :: c# code examples 
Csharp :: entity framework id not auto increment 
Csharp :: c# list initialize 
Csharp :: calculate string length vs pixels c# 
Csharp :: unity color mix 
Csharp :: unity android keycodes 
Csharp :: degree between two points latitude longitude c# 
Csharp :: c# Least prime factor of numbers till n 
Csharp :: #movement speed c 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =