简体   繁体   中英

Azure Cloud Service - Monitoring a deployment

Is there an event raised the moment a website is published and updated?

I've tried Application_End in global.asax but that event does not seem to be raised.

I suggest to use both Kudu and Microsoft ASP.NET WebHooks preview.

Kudu is the engine behind git deployments, WebJobs, and various other features in Azure Web Sites (Kudu source is on GitHub)

With Kudu, Azure Web Sites have a support for web hooks. There is an event "PostDeployment" that will be invoked whenever a deployment is complete with the result of that deployment.

Microsoft ASP.NET WebHooks preview provides a common model for receiving and processing WebHooks from any number of WebHook providers includign support for Kudu (Azure Web App Deployment).

So you may use Kudu WebHooks to get notified when an update has been deployed. (But that will require using Git Deploy instead of other ways to publish your web site).

Here is the way to do it : First Install the Microsoft.AspNet.WebHooks.Receivers.Azure Nuget package. The, Add these two lines to the WebApiConfig.Register method:

    config.InitializeReceiveKuduWebHooks();
    config.InitializeReceiveAzureAlertWebHooks();

Then Add a handler :

public class KuduWebHookHandler : WebHookHandler
{
public KuduWebHookHandler()
{
    Receiver = "kudu";
}

public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
{
    // Convert to POCO type
    KuduNotification notification = context.GetDataOrDefault<KuduNotification>();

    // Get the notification message
    string message = notification.Message;

    // Get the notification author
    string author = notification.Author;

    return Task.FromResult(true);
}
}

Then configure a secret that can validates that the WebHook requests indeed come from Kudu. Use high-entropy values such as a SHA256 hash or similar, which you can get from http://www.freeformatter.com/hmac-generator.html . Also, set them through the Azure Portal instead of hard-coding them in the Web.config file Also, set them through the Azure Portal instead of hard-coding them in the Web.config file.

There is a more complete Post on the subject here ( http://blogs.msdn.com/b/webdev/archive/2015/10/04/receive-webhooks-from-azure-alerts-and-kudu-azure-web-app-deployment.aspx )

Hope this helps Best regards Stéphane

I figured it out. In the Application_Start event I bind

RoleEnvironment.Stopping += RoleEnvironmentStopping;

private void RoleEnvironmentStopping(object sender, RoleEnvironmentStoppingEventArgs e)
{
       // do something ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM