Solved

Asp.Net getting users UPN from Active Directory

Posted on 2013-02-06
3
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

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)…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

636 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