I have an ASP.NET MVC site and a Web API. In a controller action of the MVC site I do:
public ActionResult ActionAsync()
{
string result = MakeAsyncRequest().Result;
return View("Index", (object)result);
}
MakeAsyncRequest() is as follows:
private async Task<string> MakeAsyncRequest()
{
using (var client = new HttpClient())
{
Task<string> response = client.GetStringAsync("http://localhost:55286/api/Home");
DoSomething();
return await response;
}
}
When I debug I see DoSomething() being executed (it's just a void), also the WebAPI gets called and returns a string, but then the return of MakeAsyncRequest doesn't happen and the browser stays indefinitely waiting for the server to return something.
Why is this? Something to do with the client being an ASP.NET MVC site?