Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
<fieldset>
        <legend>Log in Form</legend>
        <ol>
            <li>
                @Html.LabelFor(m => m.UserName)
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </li>
            <li>
                @Html.LabelFor(m => m.Password)
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </li>
        </ol>
        <input type="submit" value="Log in" />
    </fieldset>

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
Karthik
Posted
Updated 14-May-13 3:04am
v2
Comments
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

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

Will try and get back to you.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900