Search code examples
c#azureasp.net-web-api2azure-web-app-servicewarm-up

Azure warm up on web api is not working


I have a website with some webservices written with web api 2 and .net 4.6. I want the application to be initialized when I restart the site or when I spin up a new instance (on Azure app service).

I have this code in webconfig:

<configuration>
 ,,,,
  <system.webServer>

       ...

  <applicationInitialization doAppInitAfterRestart="true">
  <add initializationPage="/"  />
  <add initializationPage="/api-v2/warmup/get"  />
</applicationInitialization>

I have this controller:

public class WarmupController : ApiController
{
   [HttpGet]
    [RequireRole(UserRole.None)]
    [IgnoreTypeScriptGeneration]
    public IHttpActionResult Get()
    {
        Log.Information($"Warming up started. {Environment.MachineName}");
         // my warm up code
         Log.Information($"Warming up succeeded. {Environment.MachineName}");
        return Ok();
    }

I cannot see any logs. Not when I restart the site nor when I do scale out. I've tried to call my api using postman without any headers (just a get to http://xxx//api-v2/warmup/get and it worked fine and also wrote to my logs.

I've already read this thread: Cannot warm up pages using applicationInitialization in webconfig

-There is no Ip restrictions on the Azure nor on the webconfig

-There is no url rewrites in webconfig ( like for https or for www.)

-There is no external system involved (like a CMS) so I shouldn't need ot send the hostName but I've also tried to send that and it didn't work


Solution

  • So I've finally managed to make it work!

    The problem was in my code and not in the settings.

    There was a part in the start up code that was adding a check to the requests and if it was from the localhost it was stopping the processes.

    So lesson learned the hard way! :)

    Check webconfig for redirects and rewrites Check the code for stuff that do the same thing