A few things to point out here. When your role begins, it uses something called IISConfigurator to programmatically program in IIS and create applications, vdirs, application pools, etc., as defined in Service Definition. This is done once at startup.
Remember that the w3wp.exe process that hosts your site is completely separate from RoleEntryPoint, which you can use to run the code. This way you cannot just call RoleEntryPoint.RequestRecycle () and expect IIS to restart (it won't).
One solution you can try if you have to restart IIS is to programmatically do this. Here is my 3-line solution for restarting IIS on Windows Azure:
var mgr = new ServerManager(); var azurePools = mgr.ApplicationPools.Where(p => Guid.TryParse(p.Name)); azurePools.ToList().ForEach(p => p.Recycle());
I use the knowledge that application pools are GUIDs in Windows Azure to filter them out to those that interest me.
Now you just need a way to run this code from an elevated state on demand in each instance. This is a common problem with many solutions. Perhaps each instance of a file or table poll for a signal to run this code when you need to restart IIS.
dunnry
source share