Azure 云服务 - 监控部署

Azure Cloud Service - Monitoring a deployment

是否有网站发布和更新时引发的事件?

我在 global.asax 中尝试过 Application_End,但似乎没有引发该事件。

我建议同时使用 Kudu 和 Microsoft ASP.NET WebHooks 预览。

Kudu 是 git 部署、WebJobs 和 Azure 网站中各种其他功能的引擎(Kudu 源位于 GitHub)

借助 Kudu,Azure 网站支持 Web 挂钩。有一个事件 "PostDeployment" 将在部署完成并显示该部署结果时调用。

Microsoft ASP.NET WebHooks 预览版提供了一个通用模型,用于接收和处理来自任意数量的 WebHook 提供程序的 WebHook,包括对 Kudu(Azure Web 应用程序部署)的支持。

因此,您可以使用 Kudu WebHooks 在部署更新时获得通知。 (但这需要使用 Git Deploy 而不是其他方式来发布您的网站)。

方法如下: 首先安装 Microsoft.AspNet.WebHooks.Receivers.Azure Nuget 包。 的,将这两行添加到WebApiConfig.Register方法中:

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

然后添加处理程序:

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);
}
}

然后配置一个可以验证 WebHook 请求确实来自 Kudu 的密钥。 使用 high-entropy 值,例如 SHA256 散列或类似的值,您可以从 http://www.freeformatter.com/hmac-generator.html 获得。此外,通过 Azure 门户而不是 hard-coding 在 Web.config 文件中设置它们 此外,通过 Azure 门户而不是 Web.config 文件中的 hard-coding 设置它们。

这里有关于这个主题的更完整的 Post (http://blogs.msdn.com/b/webdev/archive/2015/10/04/receive-webhooks-from-azure-alerts-and-kudu-azure-web-app-deployment.aspx)

希望对您有所帮助 最好的祝福 斯蒂芬

我明白了。在 Application_Start 事件中我绑定

RoleEnvironment.Stopping += RoleEnvironmentStopping;

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