Solved

Asp.Net getting users UPN from Active Directory

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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