isEmptyElementVisible And isPresent Metadata Introduction

Posted: Jul 29, 2009  1 comments  

Average Rating

Tags
Hotfix
isEmptyElementVisible
isPresent
Metadata

Share this Post

One of the latest additions in IIS configuration is new set of metadata properties that are available as a hotfix in IIS 7.0. 

"IsEmptyElementVisible" -  This property can be set to true or false and only applies to custom schema in which you have an attributeless element that is not part of a collection and is not defining a collection.  This metadata property allows a user to force configuration of this kind to be visible in applicationHost.config. 

"isPresent" - This compliments the above metadata by providing a bool value which will inform a user that a particular configuration element as described above will be physically present in the applicationHost.config file. 

Below is some example schema where 'myElement' is the particular element that I would like to use with these two metadata properties. 

<configSchema>
  <sectionSchema name="system.webServer/customSchema">
    <element name="myElement">
    <attribute name="isTimed" type="bool" defaultValue="false" />
    <attribute name="isShort" type="bool" defaultValue="true" />
      <collection addElement="add" clearElement="clear" removeElement="remove">
        <attribute name="value" type="string" required="true" isUniqueKey="true" />
      </collection>
    </element>
  </sectionSchema>
</configSchema>

Given this schema, the below code will help make use of these new metadata properties.  In this example, I am using C# wrapper code for the AHADMIN library.

AppHostWritableAdminManager writableManager = new AppHostWritableAdminManager();

IAppHostElement element = writableManager.GetAdminSection("system.webServer/customSchema", "MACHINE/WEBROOT/APPHOST");

IAppHostElement myElement = element.GetElementByName("myElement");

myElement.SetMetadata("isEmptyElementVisible", true);

writableManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

writableManager.CommitChanges();

// at this point 'myElement' should have been made present in applicationHost.config, this can be checked with "isPresent" below 

AppHostAdminManager readableManager = new AppHostAdminManager();

IAppHostElement element = readableManager.GetAdminSection("system.webServer/customSchema","MACHINE/WEBROOT/APPHOST");

IAppHostElement myElement = element.GetElementByName("myElement");

object metadata = myElement.GetMetadata("isPresent");

Console.WriteLine(metadata.ToString().ToLower());

 

 

If this solves a problem for you, more information can be found about this hotfix as well as how to download it below.

http://support.microsoft.com/kb/970773

 

 

Submit a Comment

  • Plain text is accepted.
  • URLs starting with http:// are converted to links.