Because of the need to maintain the site, you can automatically redirect all site HTTP to the specified static page.
The main use of IIS to operate is "Microsoft.Web.Administration.dll".The library can not be found in the reference and stored in the "C:\Windows\System32\inetsrv" directory.
Microsoft.Web.Administration.ServerManager
This class is a class that operates on IIS.
varSiteName ="admin.rapid.com"; using(Servermanager Servermanager =NewServermanager ()) { //get IIS site information. varsite =Servermanager.sites[sitename]; //Obtain the "Web. config" File configuration information under the site root directory. varConfig =site. Getwebconfiguration (); //get the "ConfigurationSection httpredirectsection = config. GetSection ("System.webserver/httpredirect"); /** Set node parameters. * Enabled: whether to enable. * Destination: Destination URL or file. * Exactdestination: * httpresponsestatus:*/httpredirectsection["enabled"] =false; httpredirectsection["Destination"] =@"http://www.rapid.com/error/500$s$q"; httpredirectsection["exactdestination"] =true; httpredirectsection["Httpresponsestatus"] =@"Temporary"; //recycle the application pool. Servermanager.applicationpools[sitename]. Recycle (); //submitted. servermanager.commitchanges (); }
Comments are described.
Because the "Web. config" file under the site root is modified directly after submission, the application pool reclamation operation is required to take effect.
C # uses code to manipulate IIS