Automatically install Application Initialization in Azure Web Role (SDK v1.8, Windows Server 2012)

时光怂恿深爱的人放手 提交于 2019-12-01 04:41:20

First you'll need to install the feature using a startup task:

PKGMGR.EXE /iu:IIS-ApplicationInit

And then you'll need to configure your site in IIS (startMode and preloadEnabled):

public class WebRole : RoleEntryPoint
{
    public override void Run()
    {
        using (var serverManager = new ServerManager())
        {
            var mainSite = serverManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"];
            var mainApplication = mainSite.Applications["/"];
            mainApplication["preloadEnabled"] = true;

            var mainApplicationPool = serverManager.ApplicationPools[mainApplication.ApplicationPoolName];
            mainApplicationPool["startMode"] = "AlwaysRunning";

            serverManager.CommitChanges();
        }

        base.Run();
    }

    public override bool OnStart()
    {
        // For information on handling configuration changes
        // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

        return base.OnStart();
    }
}

I wrote a blog post about this and you can find a sample application on GitHub.

The web role absolutely has IIS 8.0 installed. Id you change the web role to OSVersion=3, it will deploy your app to a Windows Server 2012 image with IIS 8.0.

If you mean the VM (Azure IaaS)? What I would do is start from Windows Server 2012, remote desktop in, install the core server as you want, sysprep it, capture the image. This way you have it for re-use in your Azure Image Gallery. Then you can spin up many VMs from this base image with IIS 8.0 already set up/installed etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!