473,473 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

check if user belong to a domain against active directory without impersonation

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
Nov 19 '05 #1
3 2109
hi,

These links were useful for a similar scenario for me.
http://www.dotnet247.com/247reference/msgs/4/20782.aspx
http://www.dotnet247.com/247referenc.../51/256427.asp
http://www.dotnet247.com/247referenc.../__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

Nov 19 '05 #2
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.LastIndexO f(@"\")
+ 1,
identification.Length - identification.LastIndexOf(@"\")-1);
string userNameFilter =
string.Format("(&(ObjectClass=Person)(SAMAccountNa me={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]" <Ka************@discussions.microsoft.com> wrote in
message news:4D**********************************@microsof t.com...
hi,

These links were useful for a similar scenario for me.
http://www.dotnet247.com/247reference/msgs/4/20782.aspx
http://www.dotnet247.com/247referenc...51/256427.aspx
http://www.dotnet247.com/247referenc.../__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

Nov 19 '05 #3
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" <ca******@yahoo.com> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl...
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.LastIndexO f(@"\")
+ 1,
identification.Length - identification.LastIndexOf(@"\")-1);
string userNameFilter =
string.Format("(&(ObjectClass=Person)(SAMAccountNa me={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]" <Ka************@discussions.microsoft.com> wrote in
message news:4D**********************************@microsof t.com...
hi,

These links were useful for a similar scenario for me.
http://www.dotnet247.com/247reference/msgs/4/20782.aspx
http://www.dotnet247.com/247referenc...51/256427.aspx

http://www.dotnet247.com/247referenc.../__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
>
>
>


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Leonard | last post by:
I am using SmtpMail on a couple of ASP.NET pages. When mail is sent to an address outside the domain I get the "Could not access 'CDO.Message' object." error message. I have looked in the...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
3
by: Andy | last post by:
HI all, I'm trying to read Active Directory from within an Asp.net application which is not impersonating any domain user. I'd like to allow the site to query the Active directory, but I want...
6
by: CJM | last post by:
I use the following technique to impersonate a user in ASP, in order to query active directory: http://support.microsoft.com/default.aspx?scid=kb;EN-US;248187 Although the article indicates...
1
by: Raghu | last post by:
I have following code that validates a given user credentails against a active directory. The login part works but I can not search as it fails to return the record. Does any one have any idea...
18
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample...
0
by: Daniel Knöpfel | last post by:
Hello On our asp.net 2.0 website we impersonate every request to the identity of the user logged in. This works this way: 1. user logs in, providing username, password 2. user is authenticated...
0
by: kkos | last post by:
I noticed the following issue posted as a double-hop issue in many discussion boards but found no answers that explain how to pass the second hop with windows auth from IIS ASPX page to remote SQL...
2
by: rote | last post by:
My sceanrio is this on an asp.net 2.0 freamework. I want to use any of the data controls e.g Gridview,DetailView etc.. But i want some buttons e.g update,edit save etc to be enable or disabled...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.