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