.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Find user in AD

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net


I have an application that requires AD authentication. On top of that, the users usernames are stored in aspnet_users and they are assigned roles, so having a valid domain id is not enough to access the site. It works fine.

For users with valid domain ids who are not part of the system, I am trying to make a "request access" page. So, by the time they login I know their user id. To populate the access request form, I am trying to get the user's information from AD but it is giving me grief! I either get "Logon failure: unknown user name or bad password" or if I remove one of the lines below(deSearch.SearchRoot = de), I get no info for the user (no errors, but no inof either).


    private DirectoryEntry GetUserByUserID(string UserID)
        DirectoryEntry de = new DirectoryEntry("LDAP://blah.blah.blah");
        DirectorySearcher deSearch = new DirectorySearcher();
        deSearch.SearchRoot = de; <--- If I remove this line, no error and no data
        deSearch.Filter = "(&(objectClass=user)(SAMAccountName=" + UserID + "))";
        deSearch.SearchScope = SearchScope.Subtree;
        SearchResult results = deSearch.FindOne();

        if (!(results == null))
            de = new DirectoryEntry(results.Path);
            //            de = new DirectoryEntry(results.Path, "administrator", "

View Complete Post

More Related Resource Links

SPView query to find if the current user belongs to a Group


HI All,

I´m trying to write a query for a list view that should return all items if the current user belong to a group. If the user doesn´t belongs to this group, no items should be returned.

So far, I could find many equal examples about using the CAML Membership element in a comparison with an AssignetTo field. But not making a comparison between the current user and a specific Sharepoint Group.

Any suggestions, please?


Find User Password by Username Before Login


hi guys,

I have only username. and want to check and grab the password from the database. It is BEFORE LOGGING IN. so I don't think the build-in asp.net functions could be used, right?

thanks a lot!!

how to find User Mapping option of database properties.



Good evenning all.

Can any body tell me how to find User Mapping option of any database

in sql server 2008.

so that i can change the DB_OWNER name to AdMINISTRATOR.

Thanks to all.

Find all stored procedures/functions granted to a specific user


SQL 2005.

How can I find all routines (sp, fn) exec granted to a specific user in a given database ?

Thanks !!

Cannot find either Column "dbo" or the user-defined function or aggregate "dbo.GetCandiateID", or th



Good morning to everybody. I am not understanding why I am getting the following error (also mentioned in the subject line).

I have written the following function in SQL Server 2005:

    declare @candidate_id int
    SELECT @candidate_id = max(c.candidate_id) from dbo.candidates c
    if(@candidate_id is null)
        set @candidate_id = 1001
        set @candidate_id = @candidate_id + 1
    return @candidate_id

The function compiled properly. I have used the above function like below in the query:

select dbo.GetCandidateID()

I am getting the following error:

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.GetCandidateID", or the name is ambiguous

User Control Lib + ComponentResourceKey + StyleDictionary = Cannot Find Public Type

I'm trying to create a style resource dictionary file that can be used across all applications that use a user control defined in a user control lib. 

I added a resource dictionary called StyledUserControlLibDictionary.xaml to the StyledUserControlLib.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

How can I find from a single query that a user has which permission on a specific table


Hi All,

How can I find from a single query that a user  has which permission on a specific table. I have a Table named "Property_Address" and a User "ABC" doing update on this table. How can I revoke permissions on this table from this user and how can I find which permissions this user have on Property_Address Table.

Any help would be appreciate.

Find User info by UserId


I'm sorry, this feels like such a stupid question. But here goes..

Every user on my page have their own guestbook on their profile. To show their guestbook I've used a QueryString with UserId, and it shows the specific users recieved messages. I also have the UserId of the profile that sended the message, but I would of course like to view the senders username instead of the UserId. The guestbook database looks like this..


I'd like to get info from the Users table and my ProfileTable for the senders username and profile image, how do I do that inside the DataList I've already used to show the users messages? I can't seem to find a way to get the Senders info, it will only show the User Info of the users who's guestbook i'm viewing.

I'm sorry for sounding so confusing, I hope someone can help me out..

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Choosing Between a User Control or Web Part for SharePoint

SharePoint will only display Web Parts on a page. However, there are publicly available shims that allow you to write user controls and have them be displayed as a Web Part. From SharePoint's point of view, the shim is a Web Part. From the point of view of the user control, the shim is simply a control in .NET that is including the user control

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

How to track the changes of user contacts(colleagues) by using SharePoint API

We might have seen colleague tracker web part which keep tracks the changes made in our contacts/colleagues details like profile/lists/sites. The same tracking mechanism can be implemented by using MOSS API in any custom web part/ web control/ feature/web service...

UserProfile.GetColleagueChanges is the method which returns all changes happened with the contacts, this method also accepts a Query (UserProfileChangeQuery) where we can specify different parameters to filter the changes

Configuring User Profiles in SharePoint Server 2010

Note: I've added the necessary links relating to SharePoint Server 2010 prerequisites, along with instructions for configuring the user profile synchronization service, at the end of this

User Defined Functions in Microsoft SQL Server

User Defined Functions are compact pieces of Transact SQL code, which can accept parameters, and return either a value, or a table. They are saved as individual work units, and are created using standard SQL commands. Data transformation and reference value retrieval are common uses for functions. LEFT, the built in function for getting the left part of a string, and GETDATE, used for obtaining the current date and time, are two examples of function use. User Defined Functions enable the developer or DBA to create functions of their own, and save them inside SQL Server.

Building Re-Usable ASP.NET User Control and Page Libraries with VS 2008


I am having problems with a user control. I want my solution to have a separate project for holding my user controls.

The main project can get a reference to this user control project and can import this user control dll into my main project. 

Thanks in advance,

Dheeraj Mittal


Multiple Instances of User Control


I have a user control that I place on a page severl times.  When I make a selection on a ddl in one one control the SelectedIndexChanged event fires for all the control on the page for that ddl.  So I get duplication of an insert that I do.  Is there a way to make sure these events are isolated so this doesn't happen.


How to let user edit selected gridview columns, not entire row



I've got a gridview I would like to let the user edit a couple of columns.  Seems like everything I'm coming across so far makes the entire row editable.  

Hopefully the solution isn't too complicated.  Can someone point me in the right direction?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend