Solved

Asp.Net getting users UPN from Active Directory

Posted on 2013-02-06
3
265 Views
Last Modified: 2013-11-18
Hi..
Running a .net web app and am truing to get the currently logged in users User Principal Name from AD.

I'm using the System.DirectoryServices.AccountManagement.UserPrincipal.Current property to achieve this...

I understand that I need to run the application as a user that has read access to AD, but am not sure how my web.conf file should be set up to achieve this..

I currently have...

<identity impersonate="true"
                   userName="domain\someuser"
                   password="somepass"/>

... in my web.conf and the nominated user has read access to AD, the problem is that it always reports this users UPN and not the user that's actually running the application...

I know this is a bit obvious, but I'm struggling to get the web application to run in the context as the actual user who is calling the application..

If I remove the userName/password from that tag, i get the following error...
"System.DirectoryServices.DirectoryServicesCOMException"

Can someone de-mystify this for me please??

Thanks in advance..
0
Comment
Question by:jcm4101
  • 2
3 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 38862975
Hi jcm4101,

Do you have authentication mode set to Windows?

Check "Configuring Windows Authentication" section:
http://msdn.microsoft.com/en-us/library/ff647405.aspx
0
 

Author Comment

by:jcm4101
ID: 38862996
HI, thanks for your reply...

I can confirm that the relavent bits of my web.conf now look like this..
<system.web>
        <authentication mode="Windows"/>
        <identity impersonate="true"/>
...
...
...

</system.web>

This results in the exception below being thrown...
System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.

Thanks again

D
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 500 total points
ID: 38863061
Have you checked that anonymous access is disabled in IIS configuration?


What are you trying to do when you get an error? Can you show the code?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now