Click here to Skip to main content
11,920,353 members (54,217 online)
Rate this:
Please Sign up or sign in to vote.
I'm writing a web-app that is required to present users with a login screen.

Users can enter username/password and select a domain from a dropdown list.

how to enumerate all available domains in the server's AD forest even before user login after basic authentication? I came to know that it should be coded in Application_Start. But dont know how and what to do?

Here is my login web form which should authenticate in Active Directory

        <legend>Log in Form</legend>
                @Html.LabelFor(m => m.UserName)
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
                @Html.LabelFor(m => m.Password)
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
        <input type="submit" value="Log in" />
how to give here with a dropdown list under user name and password and should populate with list of all available domains...?

Please guide me..

Kindest Regards
Posted 14-May-13 2:05am
Edited 14-May-13 4:04am
David_Wimbley 14-May-13 13:45pm
Can you post the code that you have currently to get all available domains from servers AD forrest? You say you've got it implemented in your Application_Start but it would have to be in the controller and returned using a model to your view...not your app_start method.
sarvankarthik 14-May-13 13:48pm
Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, "yourDomain", "username", "password"));

Forest forest = domain.Forest;

DomainCollection domains = forest.Domains;

this is the code that enumerate domains from AD.. But how to place this code in MVC approach and how to link it to html dropdownlist helper..

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Sorry, i just saw you replied. Thanks first of all.

Will try and get back to you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web01 | 2.8.151120.1 | Last Updated 27 Apr 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100