title: Get Windows Username in ASP.NET without System.Web
body: <p>I have a reporting dll that is used in ASP.NET (Windows Authentication) and winforms projects. Sometimes it needs the username so if it was running in ASP.NET it would use:</p>
  
  <pre><code>System.Web.HttpContext.Current.User.Identity.Name;
  </code></pre>
  
  <p>and in windows</p>
  
  <pre><code>WindowsIdentity.GetCurrent().Name
  </code></pre>
  
  <p>Now I am trying to move to .NET 4 Client Profile so I need to avoid the System.Web reference in the reporting dll. Is there an alternative way to get the Windows Username for when the dll is running in ASP.NET which won't use System.Web. The only way I can currently see to avoid System.Web is to pass the Username as a parameter which will be a pain to adjust for in every report.</p>