Condividi tramite


Extending the IIS Manager Home page

IIS Manager provides a lot of extensibility points for developers, one of them is the new Home page or Control Panel. The new Home page allows end users to group their features based on different types of categories, including Area (IIS, ASP.NET and Management) and Category (Application Development, Security, Server Features, etc).

When you are registering a new page for IIS Manager you get to choose where you want your page to be shown, including the option of adding your own category to it. All of this is done through the IControlPanel interface and the related ModulePageInfo, ControlPanelCategoryInfo and ControlPanelCategorization. The following illustration explains what each class represents.

Control Panel

The following code shows how you can register a new page in the IIS Manager Control Panel:

IControlPanel controlPanel = (IControlPanel)GetService(typeof(IControlPanel));

//------------------------------------------------------
// Registration without a category
ModulePageInfo modulePage =
new ModulePageInfo(this, typeof(ModulePageInfo), "No-Category provided");
controlPanel.RegisterPage(modulePage);

Default Category 

However you can also use any of the existing categories:

IControlPanel controlPanel = (IControlPanel)GetService(typeof(IControlPanel));

ModulePageInfo modulePage =
new ModulePageInfo(this, typeof(ModulePageInfo), "IIS-Category provided");
controlPanel.RegisterPage(ControlPanelCategoryInfo.Iis, modulePage);

IIS Category 

You can also provide a categorization category for your page:

IControlPanel controlPanel = (IControlPanel)GetService(typeof(IControlPanel));

ModulePageInfo modulePage =
new ModulePageInfo(this, typeof(ModulePageInfo), "AppDev-Category provided");
controlPanel.RegisterPage(ControlPanelCategoryInfo.ApplicationDevelopment, modulePage);

Category Categorization

Finally you can also create your own categories. Note that you should register your category only once and before using it to register a page, this is important if you are registering a lot of pages from different modules. 

//------------------------------------------------------
// Create a new category registered for Area Categorization
IControlPanel controlPanel = (IControlPanel)GetService(typeof(IControlPanel));

// Find the Area Categorization
ControlPanelCategorization areaCategorization = null;
foreach (ControlPanelCategorization categorization in controlPanel.Categorizations) {
    if (categorization.Key == ControlPanelCategorization.AreaCategorization) {
areaCategorization = categorization;
break;
    }
}
// Create the new Category
ControlPanelCategoryInfo myCategory =
new ControlPanelCategoryInfo(
    "MyCompany",
    "My Company's Category",
    "This is the description for my category",
areaCategorization);
// Register it with the Control Panel
controlPanel.RegisterCategory(myCategory);

// Finally use it
ModulePageInfo modulePage =
new ModulePageInfo(this, typeof(ModulePageInfo), "Custom-Category provided");
controlPanel.RegisterPage(myCategory.Name, modulePage);

Custom Category 

You can download the code for this sample:

Sample Code  

You can also extend the set of Tasks shown in the Home page, that is done through the IHomepageTaskListProvider or the new HomePageExtension which provides additional support, but I will leave this for a future blog.