Azure app or cloud service, run some code before load balncer


In case of Cloud Service in Azure (maybe also App Service), how can I run some code before the service become available in swap or in case of new instance.

for example, loading data to cache before the first user have access.


<h3>Cloud Services with Roles</h3>

Place your app init code inside OnStart().

From <a href="https://msdn.microsoft.com/library/azure/microsoft.windowsazure.serviceruntime.roleentrypoint.onstart.aspx" rel="nofollow">https://msdn.microsoft.com/library/azure/microsoft.windowsazure.serviceruntime.roleentrypoint.onstart.aspx</a>:

<pre class="lang-cs prettyprint-override">public class WorkerRole : RoleEntryPoint { public override bool OnStart() { try { // Add initialization code here } catch (Exception e) { Trace.WriteLine("Exception during OnStart: " + e.ToString()); // Take other action as needed. } return base.OnStart(); } } <blockquote>

Before the OnStart method returns, the status of the role instance is set to Busy and the instance is not available through the load balancer.

If the OnStart method returns false, the role instance is immediately stopped. If the method returns true, Windows Azure starts the role by calling the Run method. In general, you should avoid returning false from the OnStart method.

</blockquote> <h3>App Service</h3>

Use the <a href="https://www.iis.net/downloads/microsoft/application-initialization" rel="nofollow">Application Initialization</a> IIS module. The mechanism is described in detail here - <a href="http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/" rel="nofollow">http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/</a>


<pre class="lang-xml prettyprint-override"><system.webServer> <applicationInitialization > <add initializationPage="/warmup-cache.php" hostName="site.azurewebsites.net"/> </applicationInitialization> <system.webServer>


  • New-AzureSBAuthorizationRule error when creating authorization for a Service Bus Queue
  • Azure Connection String - Object Reference not set to an Instance of an Object
  • I need to automate SQL Azure database backup in SQL Script files. How can i do so?
  • Install WindowsAzure.Storage to PCL targeting Xamarin platforms
  • Azure Storage access from Azure web site
  • Get-AzureStorageBlobContent Exception to download a blob
  • How can I CHMOD files/directories on Windows Azure?
  • Is there a way to secure an Azure Function that will only be called from a specific Azure Logic App?
  • WCF tracing in Azure production
  • Azure PowerShell - Object reference not set to an instance of an object
  • Azure Subscription not found - new portal
  • Azure Blob Storage Upload Error: (403) Forbidden
  • Windows Azure Authentication Provider is not enabled
  • Unable to load DLL 'sqlite3.dll': The specified module could not be found in UWP Xamarin.F
  • Configuring Remote Desktop for Worker role in the new portal
  • Azure Stack Table Storage: Value for HTTP headers not in correct format
  • Android - Issue with async tasks
  • Must I persist Activity data when onStop() fires?
  • Current activities onResume() is not called when another Activity is launched from lock screen via n
  • Email address validation using corona sdk
  • PouchDB on Cloudant
  • Microsoft Chart Controls for Microsoft .NET Framework 4.0
  • ConfigurationBuilder not working in azure function
  • Regex for URL rewrite with optional query string parameters
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • Other than Linq to SQL does anything else consume INotifyPropertyChanging?
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • Switch to popup in python using selenium
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Why winpcap requires both .lib and .dll to run?
  • Cannot Parse HTML Data Using Android / JSOUP
  • JTable with a ScrollPane misbehaving
  • Java static initializers and reflection
  • unknown Exception android
  • reshape alternating columns in less time and using less memory
  • Observable and ngFor in Angular 2
  • failed to connect to specific WiFi in android programmatically
  • Unable to use reactive element in my shiny app
  • How can I use threading to 'tick' a timer to be accessed by other threads?