Solved

Asp.Net getting users UPN from Active Directory

Posted on 2013-02-06
3
267 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

19 Experts available now in Live!

Get 1:1 Help Now