The following is a collection of records that are tested locally and deployed to Azure from a recurring recycle configuration that requires modifying the Azure cloud service modifier pool.
One, Win10 modify the configuration of the specified site application pool
1. Modify the IIS program pool code as follows:
Reference namespace using Microsoft.Web.Administration;
//Initialize IIS operation class using (Servermanager Servermanager = new Serverm Anager ()) {var siteName = "website";//website name var siteapplication = Servermanager.s Ites[sitename]. Applications.first ();//site corresponding to the first application var apppoolname = siteapplication.applicationpoolname;//Application corresponding to the application pool name var AppPool = servermanager.applicationpools[apppoolname];//application pool AppPool.Recycling.Disallow Rotationonconfigchange = true;//Prevent recycling When configuration changes occur appPool.Recycling.PeriodicRestart.Time = timespan.fromseconds (0 );//Prohibit fixed time interval recovery appPool.Recycling.PeriodicRestart.Schedule.Add (new TimeSpan (4, 0, 0));//increase recovery at a specific time 4 o'clock in the morning Servermanager.commitchanges ();//Submit Change Console.WriteLine ("Modified successfully"); }
Servermanager's API Reference MSDN Https://msdn.microsoft.com/zh-cn/library/microsoft.web.administration.servermanager_ Members (v=vs.90). aspx
Modifications to the IIS configuration are specific to the Https://www.iis.net/configreference/system.applicationhost/applicationpools
2. Permission Configuration
I had the opportunity to appear "file name: Redirection.config Error: Unable to read configuration file due to insufficient permissions"
You need to add user Computername\iis_iusrs operation permissions to the file Redirection.config, C:\Windows\System32\inetsrv\config.
Ii. Azure Cloud Service modifies the configuration of the current Webrole application pool
1. Modify the cloud service Servicedefinition.csdef file so that the program has permissions to modify IIS configuration
Add <runtime executioncontext= "elevated"/> the location is as follows:
2. The Web role starts by modifying the IIS configuration information and adding the program code in the OnStart () method of the Web role WebRole.cs
If you are adding an existing Web site as a Web role, you need to add the WebRole.cs class in the format:
Add the IIS operation code to the OnStart method as follows (note can refer to the above):
using (Servermanager Servermanager = new Servermanager ()) { var siteName = RoleEnvironment.CurrentRoleInstance.Id + "_web"; var siteapplication = Servermanager.sites[sitename]. Applications.first (); var apppoolname = siteapplication.applicationpoolname; var apppool = Servermanager.applicationpools[apppoolname]; AppPool.Recycling.DisallowRotationOnConfigChange = true; AppPool.Recycling.PeriodicRestart.Time = timespan.fromseconds (0); APPPOOL.RECYCLING.PERIODICRESTART.SCHEDULE.ADD (New TimeSpan (0, 0)); Servermanager.commitchanges (); }
WIN10 application modifies IIS program pool configuration and Azure cloud service modifier pool configuration to avoid automatic recycling