चूंकि आप एक खिड़कियों नेटवर्क पर हों, तो आप सक्रिय निर्देशिका क्वेरी करने के लिए उपयोगकर्ता के लिए खोज और फिर इसे गुण है प्राप्त करने के लिए इस तरह के ईमेल के रूप में की जरूरत है
यहाँ, एक उदाहरण समारोह DisplayUser
कि एक खिड़कियों प्रमाणीकृत नेटवर्क पर एक IIdentity
दिया है पाता है उपयोगकर्ता के email
:
public static void Main() {
DisplayUser(WindowsIdentity.GetCurrent());
Console.ReadKey();
}
public static void DisplayUser(IIdentity id) {
WindowsIdentity winId = id as WindowsIdentity;
if (id == null) {
Console.WriteLine("Identity is not a windows identity");
return;
}
string userInQuestion = winId.Name.Split('\\')[1];
string myDomain = winId.Name.Split('\\')[0]; // this is the domain that the user is in
// the account that this program runs in should be authenticated in there
DirectoryEntry entry = new DirectoryEntry("LDAP://" + myDomain);
DirectorySearcher adSearcher = new DirectorySearcher(entry);
adSearcher.SearchScope = SearchScope.Subtree;
adSearcher.Filter = "(&(objectClass=user)(samaccountname=" + userInQuestion + "))";
SearchResult userObject = adSearcher.FindOne();
if (userObject != null) {
string[] props = new string[] { "title", "mail" };
foreach (string prop in props) {
Console.WriteLine("{0} : {1}", prop, userObject.Properties[prop][0]);
}
}
}
इस देता है:
संपादित करें: आप 'बुरा उपयोगकर्ता/कूटशब्द त्रुटियों' खाता है कि कोड के अधीन ही उन डोमेन पहुँच होनी चाहिए मिलता है। यदि आप एएसपीनेट में कोड चलाते हैं तो वेब एप्लिकेशन को डोमेन एक्सेस के साथ क्रेडेंशियल्स वाले एप्लिकेशन पूल के तहत चलाया जाना चाहिए। अधिक जानकारी के लिए
here देखें
स्रोत
2010-10-21 10:27:12
आप अपने आवेदन में memebership प्रदाता का उपयोग कर रहे अपने स्वयं के गुण आदि जोड़ सकते हैं? – Restuta
नहीं, मेरा ऐप। विंडोज प्रमाणीकरण का उपयोग कर इंट्रानेट पर है। –