Re: check if user belong to a domain against active directory without



As a side note, it may be beneficial to use FindAll() and iterate
through the returned SearchResultCollection instead of using FindOne(). This
is to prevent against a known leak in .NET 1.1 (fixed in 2.0, however) where
the underlying COM object is not released. Remember to call Dispose() on
your DirectorySearcher and DirectoryEntry objects when you are finished with
them -- the finally{} section of an exception handler is a good place to do
this, that way it gets disposed regardless of whether an exception occurs or
not.

-- Sean M

"Caspy" <caspases@xxxxxxxxx> wrote in message
news:emJt51OmFHA.3120@xxxxxxxxxxxxxxxxxxxxxxx
> Thanks for your reply. Actually, I have the code block work fine in
> WinApps
> to access to LDAP. It also works in ASP.Net with windows authentication
> and
> imperonation enabled. I just cannot make it work in form authentication
> without imperonation. The problem is how to set the security context.
>
> Here is the method:
>
> public static bool FindUser(string identification, ref string FirstName,
> ref string LastName)
> {
> bool result = false;
> string _path = "GC://";
>
> // Setup the filter
> identification =
> identification.Substring(identification.LastIndexOf(@"\")
> + 1,
> identification.Length - identification.LastIndexOf(@"\")-1);
> string userNameFilter =
> string.Format("(&(ObjectClass=Person)(SAMAccountName={0}))",
> identification);
>
> // Get a Directory Searcher to the LDAPPath
> DirectorySearcher searcher = new DirectorySearcher(_path);
> if (searcher == null)
> {
> return false;
> }
>
> // Add the properties that need to be retrieved
> searcher.PropertiesToLoad.Add("givenName");
> searcher.PropertiesToLoad.Add("sn");
>
> // Set the filter for the search
> searcher.Filter = userNameFilter;
>
> try
> {
> // Execute the search
> SearchResult search = searcher.FindOne();
>
> if (search != null)
> {
> FirstName = SearchResultProperty(search, "givenName");
> LastName = SearchResultProperty(search, "sn");
> result = true;
> }
> else
> result = false;
> }
> catch (Exception ex)
> {
> result = false;
> }
>
> return result;
> }
>
>
> Thanks,
>
> --Capsy
>
> "Kannan.V [MCSD.net]" <KannanVMCSDnet@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message news:4D97346C-53EE-4574-AD04-C310F1F73DB7@xxxxxxxxxxxxxxxx
>> hi,
>>
>> These links were useful for a similar scenario for me.
>> http://www.dotnet247.com/247reference/msgs/4/20782.aspx
>> http://www.dotnet247.com/247reference/msgs/51/256427.aspx
>>
> http://www.dotnet247.com/247reference/System/Data/PropertyCollection/__discussions
>>
>> hope this helps
>> --
>> Kannan.V
>> Home : http://www.kannanv.com
>> Blog : http://kannanv.blogspot.com
>> Web : http://www.DotnetLounge.net
>>
>> "Any one who has never made a mistake has never tried anything new" -
> Einstein
>>
>>
>> "Caspy" wrote:
>>
>> > I just get stuck on how to check if a user is a member of network
> (domain).
>> > I am building an internal tracking system with ASP.Net with Form
>> > authentication. When an user is added into the system, it check if the
> user
>> > is a member of the domain account against Global Catalog. If not, the
> user
>> > is not allowed to added in. If is, get the user's first name and last
> name
>> > and insert into the database.
>> > Because the system need access to other resource, I don't want to use
>> > impersonation. Changing WindonIdentity with impersonation at run time
>> > is
>> > also not a choice because the web server is running on Windows 2000.
> Based
>> > on the Security context, how to check if a user in the system or not?
> Thank
>> > you in advance.
>> >
>> > --Caspy
>> >
>> >
>> >
>
>


.



Relevant Pages

  • ASP.NET 2.0 with ADAM - COMException when accessing roles
    ... AuthorizationStoreRoleProvider for retrieving the role information. ... (Exception from HRESULT: 0x80070577) ... Authentication Type: Forms ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • ASP.NET making COM calls on IIS6
    ... with IIS 5 or IIS 6) if the service is installed on the same server as the ... 'Anonymous access and authentication control' ... Exception Details: System.UnauthorizedAccessException: Access is denied. ... granting access rights to the resource to the ASP.NET request identity. ...
    (microsoft.public.inetserver.iis.security)
  • Re: WebDav Authentication
    ... could you please post the complete exception info? ... conversion from string to double where indicated below. ... Dim strBody as String ... 'Get the response & store the authentication cookies: ...
    (microsoft.public.exchange2000.development)
  • Re: problem accessing ActiveDirectory through Mozill Firefox
    ... Your code is impersonating the logged on user and using that security ... you'll need Kerberos authentication to make this work. ... PropertiesToLoad property of the DirectorySearcher and read its value ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Forms Authentication and long ViewState Problem
    ... Exception Details: System.Web.HttpException: Unable to validate data. ... [HttpException: Authentication of viewstate failed. ...
    (microsoft.public.dotnet.framework.aspnet)