C # Operations IIS settings

Source: Internet
Author: User

The various properties of IIS can be easily controlled through C #.

The following shows how to operate the ISAPI and CGI restrictions for IIS through C #

(a) manual operation

(ii) Use of orders

In the Start menu run, enter cmd, and then enter

CD%windir%\system32\inetsrv

The above command switches to the path installed by IIS, and then runs Appcmd.exe. This is a new command IIS7 extremely later, IIS6 does not support

Then enter the following command to list all the Ispapi

Appcmd List Config/section:isapicgirestriction

(iii) operation of IIS through C #

First, you must make sure that IIS is installed on your computer, and after installation, the system registers a DLL by default, for example, my location is

C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Administration\7.0.0.0__31bf3856ad364e35\ Microsoft.Web.Administration.dll

Adds a reference to the DLL.

And then you can get it,

The code is:

            using (Servermanager Servermanager = new Servermanager ())            {                Configuration config = Servermanager.getapplicationhostconfiguration ();                ConfigurationSection isapicgirestrictionsection = config. GetSection ("System.webserver/security/isapicgirestriction");                ConfigurationElementCollection isapicgirestrictioncollection = Isapicgirestrictionsection.getcollection ();                foreach (configurationelement element in isapicgirestrictioncollection)                {                    string path = element["path"]. ToString ();                    string allowed = element["allowed"]. ToString ();                    String description = element["description"]. ToString ();                    String groupId = element["GroupId"]. ToString ();                                                  }}

If you monitor, you can see

You can also add Ispapi yourself

 // configurationelement addelement =                Isapicgirestrictioncollection.createelement ("add");  // addelement["path"] = @ "C:\Windows\                Abc\aspnet_isapi.dll ";                 // addelement["allowed"] = true;  // addelement["groupId"] = @ "                Contosogroup ";  // addelement["description"] = @ "                Contoso Extension ";  // isapicgirestrictioncollection.add (                AddElement);  // servermanager.commitchanges ();  

C # Operations IIS settings

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.