title: How to get controller name in WebApi Request?
body: <p>I have a logging.cs class that is used in my WebApi project to log information about the incoming request. </p>
  
  <p>The class is triggered from my Application_BeginRequest() method in my Global.asax. 
  <strong>I need to get the Controller name and the Authorization header in the request . How to do ?</strong> </p>
  
  <p>I keep playing with the HttpRequest Request object but I cannot seem to sort of harness what it is I need exactly. (Although method of the Http request seems easy enough!!) </p>
  
  <p>For the Authorization header I would think it would be as simple as "Request.Headers["Authorization"];" however this comes back as null currently.</p>
  
  <p>My code is below, any direction or advice would be greatly appreciated. 
  -Jason</p>
  
  <pre><code>namespace WCAPI.BLL
  {
      public class logging_2
      {
          private static HttpRequest Request
          {
              get { return HttpContext.Current.Request; }
          }
  
          private static HttpResponse Response
          {
              get { return HttpContext.Current.Response; }
          }
  
          public static void LogWcapiRequest(BLL.DebugTmr tmr)
          {
              if (tmr.EventType == DebugTmr.EventTypes.Null) { return; }
  
              try
              {
                  Services.AFSILog log = new Services.AFSILog();
                  log.Level = Services.LogLevels.Info;
                  log.SourceSystem = ANACore.AMTConfig.GetConfigurationValue("ConsoleLogSourceSystem");
                  if (Request.Url.IsLoopback) { log.SourceSystem += "_" + System.Environment.MachineName; }
                  log.Stamp = DateTime.Now;
                  log.Message = tmr.FormatedMsg;
                  log.Category = tmr.EventType.ToString();
  
  
                  List&lt;Services.LogData&gt; dets = new List&lt;Services.LogData&gt;();
                  dets.Add(new Services.LogData { DataType = Services.ParameterDataTypes.Int, DataKey = "Duration", DataValue = tmr.ElapsedMs.ToString() });
  
                  //This appears to be easy!! 
                  var meth = Request.HttpMethod;
                  dets.Add(new Services.LogData { DataType = Services.ParameterDataTypes.Int, DataKey = "Method", DataValue = meth });
  
                  //Now how do I get Authorization Header and Controller name ?
  
  
                  foreach (BLL.DebugTmr.Waypoint wp in tmr.Waypoints)
                  {
                      dets.Add(new Services.LogData
                      {
                          DataType = Services.ParameterDataTypes.Int,
                          DataKey = wp.Name + "Ms",
                          DataValue = wp.ElapsedMs.ToString()
                      });
                  }
  
                  log.Parameters = dets.ToArray();
                  // This is what actually writes to the log I just need add Authorization header and Controller name to my log object
                  SaveLog(log);
              }
              catch (Exception ex)
              {
                  Debug.Print("Page log create failed : {0}", ex.Message);
              }
          }
      }
  }
  </code></pre>