4

I want to retrieve the username of the logged-in user. Is it possible? The app is for intranet only.

tempid
  • 7,838
  • 28
  • 71
  • 101

1 Answers1

6

To add Windows authentication to an app, declare the 'enterpriseAuthentication' capability in the manifest.

Refer to the info in this related question for more details.

Edit:

To retrieve the domain name of the user, I believe you can use Windows.System.UserProfile.UserInformation.GetDomainNameAsync. There is also the User domain name sample on MSDN.

Community
  • 1
  • 1
Nathan Kuchta
  • 13,482
  • 2
  • 26
  • 35
  • I have already enabled `Enterprise Authentication, Internet (Client), Private Networks (Client & Server)`. I'm able to open an Intranet URL in a WebView without the credential prompt. But in my XAML code, I want to retrieve the domainname\username so I can call a WebAPI which takes the username as the input and returns some user-specific data which needs to be on the tile. – tempid Oct 05 '12 at 16:52
  • Thanks for the edit! The sample is just what I wanted. I was able to retrieve the domainname and username. Thanks Nathan!! – tempid Oct 05 '12 at 18:08
  • The relevant code in the sample is marked as async - `async void GetDNSDomain_Click(object sender, RoutedEventArgs e)` as the code is using an `async` operation - `GetPrincipalNameAsync`. I wanted to retrieve the name in the `OnNavigatedTo` event. Is there a non-async way of retrieving it? – tempid Oct 05 '12 at 18:13
  • See http://msdn.microsoft.com/en-us/library/windows/apps/hh452713.aspx for more info on working with Async methods. – Nathan Kuchta Oct 05 '12 at 19:40