I am new to SharePoint 2013 programming. I am trying to create a web part in SP 2013 where when the web part loads it will get the current user who is viewing the page and then display the properties i want for that user in the web part. Here is the code I have been trying to work with, but it keeps failing with a 401 Unauthorized when loading and checking the permissions they do show valid. Any ideas?
Dim siteURL As String = "http://server" ' String Variable to store the account name Dim accountName As String = SPContext.Current.Web.CurrentUser.Name ' To get the context of the Sharepoint site to access the data Dim clientContext As ClientContext = New ClientContext(siteURL) Dim peopleManager As PeopleManager = New PeopleManager(clientContext) Dim personProperties As PersonProperties = peopleManager.GetPropertiesFor(accountName) 'clientContext.Load(personProperties, Function(w) w.DisplayName) 'clientContext.ExecuteQuery() lblCompany2.Text = personProperties.DisplayName