SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get current user in high-trust apps at sharepoint 2013 on-premises environment. But each returned user are the same, how can i get the correct current user? Here is my code:

    public ActionResult Index()
    {
        TokenHelper.TrustAllCertificates();
        var sharepointUrl = Request.QueryString["SPHostUrl"];

        var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(new Uri(
            sharepointUrl), Request.LogonUserIdentity);

        clientContext.Load(clientContext.Web.CurrentUser, user => user.LoginName);

        clientContext.Load(clientContext.Web);
        clientContext.ExecuteQuery();

        string result = "<h2>Web title retrieved using the managed client object model</h2>";
        result += "<p>" + clientContext.Web.Title + "</p>";

        clientContext.Dispose();

        ViewBag.Content = result;
        ViewBag.User = string.Format("Current UserName:{0}", clientContext.Web.CurrentUser.LoginName);

        return View();
    }
share|improve this question

You need to enable "Pass-through authentication" in your IIS website. Follow the steps described in the following page Windows Authenticated logon configuration for Microsoft IIS7

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.