473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

DirectoryServices.AccountManagement

I'm really having a hard time using DirectoryServices.AccountManagement. I
seem to be able to get it to work fine in Visual Web Developer 2008 but when
I deploy to a IIS Server I get cast issues.

I have a screenshot here:
http://forums.asp.net/p/1210311/2131427.aspx#2131427

Unable to cast object of type
'System.DirectoryServices.AccountManagement.GroupP rincipal' to type
'System.DirectoryServices.AccountManagement.UserPr incipal'.

Jan 24 '08 #1
4 4960
"David Jenkins Toppan" <Da****************@discussions.microsoft.comwro te
in message news:1B**********************************@microsof t.com...
I'm really having a hard time using DirectoryServices.AccountManagement.
I
seem to be able to get it to work fine in Visual Web Developer 2008 but
when
I deploy to a IIS Server I get cast issues.

I have a screenshot here:
http://forums.asp.net/p/1210311/2131427.aspx#2131427

Unable to cast object of type
'System.DirectoryServices.AccountManagement.GroupP rincipal' to type
'System.DirectoryServices.AccountManagement.UserPr incipal'.
You are running in the context of a group SID, not a user account SID.
If ASP.NET is running as NT_AUTHORITY\NETWORK SERVICE or NT_AUTHORITY\LOCAL
SERVICE, then the current user SID is a group SID and the cast to a
UserPrincipal will fail (this is normal). So, you need to make sure that you
run in the context of a user account, or you need to catch this exception
and take the appropriate action.

Willy.

Jan 24 '08 #2
Are there any articles I could read that you know of that explains what I
need to do?

"Willy Denoyette [MVP]" wrote:
"David Jenkins Toppan" <Da****************@discussions.microsoft.comwro te
in message news:1B**********************************@microsof t.com...
I'm really having a hard time using DirectoryServices.AccountManagement.
I
seem to be able to get it to work fine in Visual Web Developer 2008 but
when
I deploy to a IIS Server I get cast issues.

I have a screenshot here:
http://forums.asp.net/p/1210311/2131427.aspx#2131427

Unable to cast object of type
'System.DirectoryServices.AccountManagement.GroupP rincipal' to type
'System.DirectoryServices.AccountManagement.UserPr incipal'.


You are running in the context of a group SID, not a user account SID.
If ASP.NET is running as NT_AUTHORITY\NETWORK SERVICE or NT_AUTHORITY\LOCAL
SERVICE, then the current user SID is a group SID and the cast to a
UserPrincipal will fail (this is normal). So, you need to make sure that you
run in the context of a user account, or you need to catch this exception
and take the appropriate action.

Willy.

Jan 25 '08 #3
"David Jenkins Toppan" <Da****************@discussions.microsoft.comwro te
in message news:2B**********************************@microsof t.com...
>I was trying to pull attributes like name and phone number of the current
user. This is an Intranet application I'm creating.
I see, in that case you need to make sure that "Windows Authentication" is
enabled and that you are "impersonating", and that your clients are using
IE.

Willy.
Jan 25 '08 #4
I'll read up on it. I've got the web.config already setup for Windows and
disabled Anonymous access. In IIS I've uncheck anonymous logon and selected
Integrated Windows Authentication.

I appreciate the help. If you know of a good example on the net on how to
do Impersonation that would be great. I'm still a Novice. I'm an MCSE so I
really only know AD other MS Applications.

"Willy Denoyette [MVP]" wrote:
"David Jenkins Toppan" <Da****************@discussions.microsoft.comwro te
in message news:2B**********************************@microsof t.com...
I was trying to pull attributes like name and phone number of the current
user. This is an Intranet application I'm creating.

I see, in that case you need to make sure that "Windows Authentication" is
enabled and that you are "impersonating", and that your clients are using
IE.

Willy.
Jan 25 '08 #5

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

Similar topics

12
by: hykim | last post by:
Hello, everyone. according to MSDN, there is any constructor of System.DirectoryServices.SearchResultCollection Class. if I implement DirectorySearcher.FindAll() method by myself, then how can I...
1
by: Jason Gleason | last post by:
I am using the following method in a web service that utilizes the system.directoryservices namespace: public ArrayList GetAllAppPools(){ System.DirectoryServices.DirectoryEntry apppools = new...
1
by: Enosh Chang | last post by:
Hi all, I encounter some problem in DirectoryServices, could someone help me? private void InitLoginUser() { DirectoryEntry objEntry = new DirectoryEntry(); DirectorySearcher objSearcher =...
9
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group...
5
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our...
7
by: turbon | last post by:
Hello, I am writing code, which will copy webServices from one IIS 6.0 webserver to another and using DirentoryServices to achieve this purpose. And I have problems with authentication - I get an...
2
by: =?Utf-8?B?cmloYWRk?= | last post by:
Hi, Is it not possible to use an instance of a System.DirectoryServices.AccountManagement.UserPrincipal objec to chage the Name property? For example the following code always fails with the...
7
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I am using this code to get groups for a user and getting a error (5) on the GetAuthorizationGroups() function . There are two domains. This function works on the local domain but does not work...
0
by: djnokturnal | last post by:
Hey! I am attempting to rewrite some old C# code in our code base that utilized DirectoryEntry to perform some LDAP queries. I am migrating it to the new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.