472,805 Members | 859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

ADSI using Asp.net


I am going to create intranet application using Windows Authentication
[W2k Active Directory users] using C# asp.net

I am having following problem:

1 setting windows Authentication, it will validate for all users, user name
and password from ADSI before entering into application this is working fine.
Problem Is I am going to categorize users based on their Title properties
value

Eg: if Title = Accounts that user going to Access that related pages
Likewise different users going to access different pages.
I need solution for this how to do this using windows
Authentication

- How to retrieve Active Directory users properties into intranet
application using asp.net.
Any suggestion or related link,
any help would be greatly appreciated.

Thanks

Nov 17 '05 #1
2 2340
What you want to achieve here is 2 different things:
The first thing is Authentication
The other thing is Authorization

The solution involves merging Windows Integrated Authentication with Role
Bases Authorization

Role-based Authorization is built on the premise that users are
authenticated, which is the process of identifying the user. Once identified,
the user can be authorized or, assigned roles and permissions. Credentials
like a username and password are usually provided to authenticate users, and
this information is used to create a security principal representing this
user's identity at runtime. The .NET Framework object model includes built-in
support to work with Windows

To understand how this security principal is used by the runtime it is
important to consider the relationship between the running process, the
application domain, and the assemblies loaded within that application domain

By default the process runs under the logged in user's Windows identity, and
this governs what resources can be accessed by any thread of execution within
that process, yet, each thread of execution can also be assigned an identity
which governs how role-based security checks are evaluated at runtime

ASP.NET process identity is identified by the <processModel> section of the
machine.config. Unless the worker process is asked to impersonate another
account, this is the identity that governs your Web application's access to
system resources such as the file system, the Windows registry, and the
database if integrated Windows accounts are used

When your application uses Windows authentication, ASP.NET automatically
constructs a WindowsPrincipal that is attached to the context of the current
Web request (using HttpContext.User). After the authentication process is
complete and ASP.NET has attached to object to the current request, it is
used for all subsequent .NET role-based authorization.
The Windows group membership of the authenticated caller is used to
determine the set of roles. With Windows authentication, .NET roles are the
same as Windows groups.
You can get the groups using code like this
void WindowsAuthentication_Authenticate(object sender,
WindowsAuthenticationEventArgs e)
{
String[] roleStrng = GetUserRoles();
e.User = new GenericPrincipal(e.Identity, roleStrng);
}
private string[] GetUserRoles()
{
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.Window sPrincipal);
ArrayList al = new ArrayList();

WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
Array wbirFields = Enum.GetValues(GetType(WindowsBuiltInRole));

foreach (object roleName in wbirFields)
{
try
{
if (myPrincipal.IsInRole((WindowsBuiltInRole)roleName ))
al.Add(roleName.ToString());
}
catch{};

}
return (string[])(al.ToArray(typeof(string)));
}
http://msdn.microsoft.com/library/de...SecNetch03.asp
http://www.15seconds.com/issue/041208.htm
http://www.eggheadcafe.com/articles/20020418.asp
Best Regards,
Waleed K. Mallouk

Solutions Architect

"YRao" wrote:

I am going to create intranet application using Windows Authentication
[W2k Active Directory users] using C# asp.net

I am having following problem:

1 setting windows Authentication, it will validate for all users, user name
and password from ADSI before entering into application this is working fine.
Problem Is I am going to categorize users based on their Title properties
value

Eg: if Title = Accounts that user going to Access that related pages
Likewise different users going to access different pages.
I need solution for this how to do this using windows
Authentication

- How to retrieve Active Directory users properties into intranet
application using asp.net.
Any suggestion or related link,
any help would be greatly appreciated.

Thanks

Nov 17 '05 #2
Thanks "Waleed Mallouk"

I got detailed solution from you.Now I will proceed my work.

i am having one more problem that is
-i am going to retrieve users based on Title properties in AD

Thanks
-YRao
"Waleed Mallouk" wrote:
What you want to achieve here is 2 different things:
The first thing is Authentication
The other thing is Authorization

The solution involves merging Windows Integrated Authentication with Role
Bases Authorization

Role-based Authorization is built on the premise that users are
authenticated, which is the process of identifying the user. Once identified,
the user can be authorized or, assigned roles and permissions. Credentials
like a username and password are usually provided to authenticate users, and
this information is used to create a security principal representing this
user's identity at runtime. The .NET Framework object model includes built-in
support to work with Windows

To understand how this security principal is used by the runtime it is
important to consider the relationship between the running process, the
application domain, and the assemblies loaded within that application domain

By default the process runs under the logged in user's Windows identity, and
this governs what resources can be accessed by any thread of execution within
that process, yet, each thread of execution can also be assigned an identity
which governs how role-based security checks are evaluated at runtime

ASP.NET process identity is identified by the <processModel> section of the
machine.config. Unless the worker process is asked to impersonate another
account, this is the identity that governs your Web application's access to
system resources such as the file system, the Windows registry, and the
database if integrated Windows accounts are used

When your application uses Windows authentication, ASP.NET automatically
constructs a WindowsPrincipal that is attached to the context of the current
Web request (using HttpContext.User). After the authentication process is
complete and ASP.NET has attached to object to the current request, it is
used for all subsequent .NET role-based authorization.
The Windows group membership of the authenticated caller is used to
determine the set of roles. With Windows authentication, .NET roles are the
same as Windows groups.
You can get the groups using code like this
void WindowsAuthentication_Authenticate(object sender,
WindowsAuthenticationEventArgs e)
{
String[] roleStrng = GetUserRoles();
e.User = new GenericPrincipal(e.Identity, roleStrng);
}
private string[] GetUserRoles()
{
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.Window sPrincipal);
ArrayList al = new ArrayList();

WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
Array wbirFields = Enum.GetValues(GetType(WindowsBuiltInRole));

foreach (object roleName in wbirFields)
{
try
{
if (myPrincipal.IsInRole((WindowsBuiltInRole)roleName ))
al.Add(roleName.ToString());
}
catch{};

}
return (string[])(al.ToArray(typeof(string)));
}
http://msdn.microsoft.com/library/de...SecNetch03.asp
http://www.15seconds.com/issue/041208.htm
http://www.eggheadcafe.com/articles/20020418.asp
Best Regards,
Waleed K. Mallouk

Solutions Architect

"YRao" wrote:

I am going to create intranet application using Windows Authentication
[W2k Active Directory users] using C# asp.net

I am having following problem:

1 setting windows Authentication, it will validate for all users, user name
and password from ADSI before entering into application this is working fine.
Problem Is I am going to categorize users based on their Title properties
value

Eg: if Title = Accounts that user going to Access that related pages
Likewise different users going to access different pages.
I need solution for this how to do this using windows
Authentication

- How to retrieve Active Directory users properties into intranet
application using asp.net.
Any suggestion or related link,
any help would be greatly appreciated.

Thanks

Nov 17 '05 #3

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

Similar topics

2
by: Kevin Otte | last post by:
Hi everyone, I'm pretty new to using the COM functionality in PHP. I want to administer my PC using PHP together with ADSI. My first problem is to enumerate the groups in my domain. I tried...
6
by: Miguel Orrego | last post by:
Hi, I have found some code that authenticates users agains a domain using ADSI. I then redirect to another page and pass the username they have entered as a string. However, it would be nice to...
4
by: Akhlaq Khan | last post by:
we are developing an intranet application (web based) which needs to detect the logged in user ID of the user hitting the website. the intranet is huge and based on win2k active directory (around...
1
by: Ryan Ritten | last post by:
I was wondering if anyone knew how (or if it's even possible) to cache the results of an ADSI call in asp for a longer period of time. Basically what I am doing is I have a website that loads the...
2
by: Enigma Webmaster | last post by:
Hi All, We've written a couple of functions which, when run in VB6 work fine and allow AD users to be updated. When we include the code into an ASP Page and try and update a users information...
14
by: Arran Pearce | last post by:
Hi, I am looking for a way to use System.DirectoryServices to find all users on a domain whos accounts are either locked out or disabled. I have used ADSIEdit and the mmc schema add-in to try...
3
by: Roy Osherove | last post by:
Hi folks. I have an ASP.Net application that runs a .Net dll that uses WMI and ADSI(both managed) to connect to a given IIS root and search through it. When not using the ASP.Net client, but...
0
by: Barbara Alderton | last post by:
I have a asp.net application that needs to access Active Directory information. I setup the retrieval using System.DirectoryServices to access directReports of a user together with directReports...
3
by: chat_devil | last post by:
hi, does anyone know if it is possible to remove an attribute that can not be read into the ADSI property cache/collection. i'm trying to do an eDirectory password change from .net directory...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.