title: Get sharepoint current User LoginName in C# MVC
body: <p>I have 2 Apps :</p>
  
  <ol>
  <li>Sharepoint 2013 AS a portal web</li>
  <li>MVC App</li>
  </ol>
  
  <p><strong>If i want a single sign on from sharepoint, how can i get the current user that logged in to sharepoint from my MVC App ?</strong></p>
  
  <p>The information might needed :</p>
  
  <ul>
  <li>Sharepoint login using windows authentication </li>
  <li>Flow : 
  
  <ol>
  <li>User login in sharepoint web</li>
  <li>There is a button to open my MVC App in new tab (by URL)</li>
  </ol></li>
  </ul>
  
  <p>For now i only know using REST API method. Code Existing :</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(HostURL + "/_api/Web/CurrentUser?Select=id");
  request.Method = "GET";
  request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  request.UseDefaultCredentials = true;
  request.PreAuthenticate = true;
  request.Credentials = new NetworkCredential(UserName, Password, DomainName);
  </code></pre>
  
  <p>But in my code is only get the user that i assigned in network credential. How can i get the current user that logged in to sharepoint from my MVC App ?</p>
  
  <p>Any Method will be accepted as long as i can get the user LoginName. Just tell me what should i do.</p>
  
  <p>Thank you</p>