C # uses code to manipulate IIS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.