title: Trying to get the user-agent from request in asp.net web api self host
body: <p>I'm trying to get the user-agent in a web api self host and I'm either doing it wrong, or the web api itself is altering the user agent string.</p>
  
  <p>I've tried using several methods to the get the string and they all return the same results, instead of the excepted "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.28 Safari/537.31", I only get "Mozilla/5.0".</p>
  
  <p>I've tried:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var header = request.Headers.SingleOrDefault(h =&gt; h.Key == "User-Agent").Value.First();
  
  var header = request.Headers.UserAgent.SingleOrDefault().Product.ToString();
  
  var header = request.Headers.GetValues("User-Agent").FirstOrDefault();
  </code></pre>
  
  <p>Am I doing this wrong, it's self host so I don't have a context to work with.</p>