Link to home
Start Free TrialLog in
Avatar of forsters
forstersFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Query AD from asp.net c#

Hi Experts,

This is a follow-on from an earlier question, I'm just feeling my way into querying AD from an asp.net c# web app:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27867423.html

In the code below I have a few lines that get the identity of the person logged in, I'd like to use this for my bool test so that I now look up the person logged in and confirm they exist in AD.

My plan is to then go on and retrieve certain details based on their identity:

Be grateful if someone could show me how to use my Session["username"] in the ("domain\\username") path, I have tried a few variations but clearly missing the obvious here.

protected void Page_Load(object sender, EventArgs e)
    {

        System.Security.Principal.IPrincipal user;

        user = System.Web.HttpContext.Current.User;

        System.Security.Principal.IIdentity identity;

        identity = user.Identity;

        Session["username"] = identity.Name.Substring(identity.Name.IndexOf(@"\") + 1);


               bool test = IsExistInAD("domain\\username");
               if (test == true)
               {
                   Response.Write("user exists");
               }
               else
               {
                   Response.Write("user doesn't exist");
               }

    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or

string user;
usr="domain\\" +  Session["username"] ;

bool test = IsExistInAD(USR);
Avatar of forsters

ASKER

Perfect thank you, I knew it would be something simple, was trying to contain the whole path in my " ", sighs.

Thank you so much