REST API for managing IIS
Перейти к файлу
Jimmy Campbell 3cef12b4ea Updated monitoring tests to handle new properties. 2017-10-16 16:50:45 -07:00
assets Initial commit. 2016-08-29 13:31:27 -07:00
build Update version for next release. (#142) 2017-10-11 11:24:52 -07:00
scripts Update version for next release. (#142) 2017-10-11 11:24:52 -07:00
src Added system level counters for cpu and memory usage. 2017-10-16 15:24:13 -07:00
test Updated monitoring tests to handle new properties. 2017-10-16 16:50:45 -07:00
.gitignore Added msbuild props to enable signing to be plugged in. 2017-07-12 09:24:10 -07:00
LICENSE.md Initial commit. 2016-08-29 13:31:27 -07:00
Microsoft.IIS.Administration.sln Add monitoring endpoints for website, app-pool, and webserver (#140) 2017-10-11 11:23:25 -07:00
README.md Update readme. 2017-06-19 14:59:26 -07:00
ThirdPartyNotices.txt Add third party notices. 2016-09-09 11:14:31 -07:00
appveyor.yml Files configuration endpoint (#143) 2017-10-11 09:17:58 -07:00

README.md

Microsoft IIS Administration API

Build status

Requirements:

Nano Server Installation:

There is a blog post to get up and running on Nano Server located at https://blogs.iis.net/adminapi/microsoft-iis-administration-on-nano-server.

Running Tests:

  • Open the project in Visual Studio as an Administrator and launch without debugging
  • Open another instance of the project and run the tests located in the 'test' folder
  • Tests can also be run with the CLI

Publish and Install:

  • Run PowerShell as an Administrator
  • Run the Publish.ps1 script located in the scripts directory
  • (SolutionRoot)\scripts\publish\publish.ps1
  • (SolutionRoot)\scripts\publish\bin\setup\setup.ps1 Install -Verbose

Using the new API

  1. Navigate to https://manage.iis.net
  2. Click 'Get Access Token'
  3. Generate an access token and copy it to the clipboard
  4. Exit the access tokens window and return to the connection screen
  5. Paste the access token into the Access Token field of the connection screen
  6. Click 'Connect'

Examples

Intialize Api Client

var httpClientHandler = new HttpClientHandler() {
    Credentials = new NetworkCredential(userName, password, domain)
};
var apiClient = new HttpClient(httpClientHandler);

// Set access token for every request
apiClient.DefaultRequestHeaders.Add("Access-Token", "Bearer {token}");

Get Web Sites

var res = apiClient.GetAsync("https://localhost:55539/api/webserver/websites").Result;
if (res.StatusCode != HttpStatusCode.OK) {
  HandleError(res);
  return;
}

JArray sites = JObject.Parse(res.Content.ReadAsStringAsync().Result).Value<JArray>("websites");

Create a Web Site

var newSite = new {
    name = "Contoso",
    physical_path = @"C:\sites\Contoso",
    bindings = new[] {
        new {
            port = 8080,
            is_https = false,
            ip_address = "*"
        }
    }
};
var res = apiClient.PostAsJsonAsync<object>("https://localhost:55539/api/webserver/websites", newSite).Result;
if (res.StatusCode != HttpStatusCode.Created) {
    HandleError(res);
    return;
}

JObject site = JObject.Parse(res.Content.ReadAsStringAsync().Result);