Anele Ngqandu

Anele Ngqandu

  • 1.3k
  • 429
  • 27.8k

Calling webapi2 from RegisterArea(AreaRegistrationContext context)

Jul 3 2022 2:00 PM

Hi All

Kindly assist, is there a way to call a webapi controller from RegisterArea(AreaRegistrationContext context)?

 

public override void RegisterArea(AreaRegistrationContext context)
        {
            var client = new RestClient("url");
            var request = new RestRequest("url/api/get/", Method.GET);
            request.UseDefaultCredentials = true;
            request.AddHeader("cache-control", "no-cache");
            var requestResult = client.Execute<Output>(request);
            var result = JsonConvert.DeserializeObject<Output>(requestResult.Content); //takes forever and returns null

    context.MapRoute(
       name: "Student",
      url: "submission/{controller}/{action}/{id}",
       defaults: new { controller = "Submission", action = "submission", id = UrlParameter.Optional },
       namespaces: new string[] { "Staff.Web.Areas.Student.Controllers" }
   );

}