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()
        var sharepointUrl = Request.QueryString["SPHostUrl"];

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

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


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


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

        return View();

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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