title: Calling internal (Endpoint) function in WebAPI
body: <p>I am using Hangfire to execute recurring jobs in my web API and I use System.Web.HttpContext.Current.Server.MapPath in the "RoutineMethod" function.</p>
  
  <p>But the problem is it throws object null exception.
  I searched the problem and found that recurring jobs don't use http threads, they use background threads.</p>
  
  <p>Now to resolve this problem I need to call my internal (endpoint) using httpclient.</p>
  
  <p>But to do that I need to give URL of the Web API (to generate URI). So is there any other way to call internal function using httpclient.</p>
  
  <p>My current code:</p>
  
  <pre><code>public static async Task&lt;IHttpActionResult&gt; RoutineTask()
          {
              //It was like this before.
              //await new DemoController().RoutineMethod();
              //await new DemoController().RoutineMethod2();
  
              //I am planning to do this.
              using (var client = new HttpClient())
              {
                  //But I need to give URI which I don't think is a good idea.
                  var uri = new Uri("http://localhost/DemoApp/api/DemoController/RoutineMethod");
                  await client.GetAsync(uri);
  
              }
  
              return new DemoController().Ok();
          }
  </code></pre>