IIS Administration API

IIS Administration API

Aug 22, 2017     Viewed 10237 times 11 Comments
Posted in #IIS  # IIS Administration 

Last few days I saw three cool episodes for Code Conversions show by the great Jon Galloway & Jimmy Campbell which they are talking about IIS Administration API:

What's IIS Administration API

The IIS Administration API are simply a REST API for managing Internet Information Service (IIS). The main reason that leads me to write this blog post is the entire IIS Administrations is built on top ASP.NET Core with pluggability architecture, the thing that makes me more interesting :)

Using IIS Administration API

Let me show you how easy it's to deal with the newly IIS Administration API. Before writing utilize the IIS Administration API we need some steps:

  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'

Now let us illustrate how to create a new website in IIS:

// Initialize API Client
var httpClientHandler = new HttpClientHandler() {
    Credentials = new NetworkCredential(userName, password, domain)
};
var apiClient = new HttpClient(httpClientHandler);
apiClient.DefaultRequestHeaders.Add("Access-Token", "Bearer {token}");

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

var site = JObject.Parse(result.Content.ReadAsStringAsync().Result);

In the above code I first initialize the API Client with the Access Token that we got, then I provide the website information like what we are doing in the IIS (name, path and binding).

After that I use the API PostAsJsonAsync() with the object that we created to create a new website in IIS, last thing we can verifying using the StatusCode whether the website is created or not.

We saw how easy it is to consume and use the IIS Administration API, but there many of them to let you do many many things programmatically using a RESTful APIs.

For more information you can download the source code for IIS Administration API from the IIS.Administration repository on GitHub.


11 Comments

canadian (3/28/2018 2:05:33 AM)

Hello!
cialis online , cheap cialis online , buy canadian cialis , online viagra , buy cialis ,

payday_loans (4/4/2018 10:56:15 AM)

Hello!
payday loans , buy viagra online , buy viagra online , viagra , payday loans ,

viagra_cheap (4/11/2018 1:40:00 PM)

Hello!
cialis generic , cheap cialis , viagra cheap , cheap viagra , cialis cheap ,

cialis (4/23/2018 7:37:35 PM)

Hello!
cialis , cialis , cialis , buy viagra , cheap cialis online ,

cialis (6/27/2018 4:23:39 AM)

Hello!
buy viagra , buy cialis online , buy viagra , buy viagra online , cialis ,

cialis_canada (6/30/2018 6:11:33 AM)

Hello!
cialis , viagra price , cialis , online viagra , cialis canada ,

buy_cialis (9/21/2018 3:15:19 AM)

Hello!
cheap viagra , viagra cheap , cialis , buy cialis , buy cialis ,

cialis_online (9/21/2018 7:35:54 AM)

Hello!
cialis online , cialis online , generic viagra , cheap viagra , buy cialis ,

viagra_online (9/28/2018 12:15:48 AM)

Hello!
cheap viagra , buy cialis , cialis , viagra online , cialis online ,

canadian pharmacy no prescription (10/3/2018 5:39:36 AM)

Howdy! I just want to give you a big thumbs up for the
great information you've got here on this post. I'll be returning to your blog for more soon.

canadian pharmacies that are legit (10/4/2018 10:55:05 AM)

When I initially commented I clicked the "Notify me when new comments are added" checkbox and now each time a
comment is added I get three e-mails with the same comment.
Is there any way you can remove me from that service?
Bless you!


Leave a Comment