【问题标题】:Is there an Azure Websites functionality equivalent to Azure Web Roles RoleEntryPoint是否有与 Azure Web 角色 RoleEntryPoint 等效的 Azure 网站功能
【发布时间】:2013-05-23 12:40:29
【问题描述】:

我想在 Application_Start 之前从库中运行一些代码,我想知道这是否可以仅使用 Azure 网站,或者我是否必须购买 Azure Web Role 实例并使用 RoleEntryPoint?

【问题讨论】:

    标签: asp.net-mvc-4 azure azure-web-roles


    【解决方案1】:

    您是否尝试过使用WebActivator NuGet 包?查看GitHub 以获取更多详细信息,但它的基础只是向您的应用程序添加一个属性和一个初始化方法。例如:

    using System;
    
    [assembly: WebActivator.PreApplicationStartMethod(typeof(MyApp.Bootstrapper), "PreStart")]
    
    namespace MyApp {
        public static class Bootstrapper {
            public static void PreStart() {
                // Add your start logic here
            }
        }
    }
    

    PreStart 中的代码将在 Application_Start 之前运行。

    您可以使用其他属性在关机 (ApplicationShutdownMethodAttribute) 和启动后 (PostApplicationStartMethodAttribute) 执行操作。

    【讨论】:

    • 这看起来正是我正在寻找的。您是否知道这是否需要像 Application_Start 这样的客户端浏览器访问 Web 应用程序,或者此代码是否会在没有任何客户端交互的情况下执行?
    • 它需要应用程序池先启动。缓解这种情况的唯一方法是将应用程序池配置为始终运行,但我怀疑这在 Azure 网站中是不可行的......
    猜你喜欢
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多