Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Stellt eine Auflistung von Elementen dar, die zu einer Auflistung gehören.
Syntax
HRESULT get_Collection(
[out,
retval] IAppHostElementCollection** ppCollection
);
Parameter
ppCollection
Ein Zeiger auf einen Zeiger für eine IAppHostElementCollection-Schnittstelle .
Rückgabewert
HRESULT. Mögliches Werte (aber nicht die Einzigen) sind die in der folgenden Tabelle.
| Wert | BESCHREIBUNG |
|---|---|
| S_OK | Gibt an, dass der Vorgang erfolgreich war. |
Bemerkungen
Eine untergeordnete Elementauflistung, die in der IAppHostElement::ChildElements-Eigenschaft dargestellt wird, unterscheidet sich von einer geschachtelten Elementauflistung, die in der IAppHostElement::Collection -Eigenschaft dargestellt wird. Beide Auflistungen enthalten Zeiger auf IAppHostElement-Objekte . Sie sollten jedoch die IAppHostElement::ChildElements -Eigenschaft verwenden, wenn Sie die Konfiguration nach eindeutigen untergeordneten Elementen abfragen, z. B. den system.webServer/asp Konfigurationsabschnitt. Im folgenden Konfigurationsbeispiel ist das <cache/> Element ein untergeordnetes Element des system.webServer/asp Konfigurationsabschnitts.
<system.webServer>
<asp>
<cache diskTemplateCacheDirectory="%SystemDrive%\inetpub\temp\ASP Compiled Templates" />
</asp>
</system.webServer>
Sie sollten die IAppHostElement::Collection -Eigenschaft verwenden, wenn Sie die Konfiguration für untergeordnete Elemente abfragen, die einen eindeutigen Schlüssel oder einen Schlüssel mit mehreren Attributen enthalten, z. B. den system.webServer/sites Konfigurationsabschnitt. Im folgenden Konfigurationsbeispiel sind die <site/> Elemente Sammlungselemente, und das <applicationDefaults/> Element ist ein untergeordnetes Element des system.applicationHost/sites Konfigurationsabschnitts.
<system.applicationHost>
<sites>
<site name="Default Web Site" id="1">
<application path="/">
<virtualDirectory path="/"
physicalPath="%SystemDrive%\inetpub\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
<site name="Microsoft.com" id="35">
<bindings>
<binding protocol="http"
bindingInformation="*:80:microsoft.com" />
</bindings>
</site>
<siteDefaults>
<logFile customLogPluginClsid="{FF160663-DE82-11CF-BC0A-00AA006111E0}"
directory="%SystemDrive%\inetpub\logs\LogFiles" />
<traceFailedRequestsLogging
directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" />
</siteDefaults>
<applicationDefaults applicationPool="DefaultAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
</system.applicationHost>
Beispiel
Im folgenden Codebeispiel werden alle Standorte im system.webServer/sites Konfigurationsabschnitt für den Konfigurationspfad MACHINE/WEBROOT/APPHOST angezeigt.
#pragma once
#include <stdio.h>
#include <string.h>
#include <ahadmin.h>
int main()
{
IAppHostAdminManager * pMgr = NULL;
IAppHostElement * pParentElem = NULL;
IAppHostElementCollection * pElemColl = NULL;
IAppHostElement * pElem = NULL;
IAppHostPropertyCollection * pElemProps = NULL;
IAppHostProperty * pElemProp = NULL;
HRESULT hr = S_OK;
BSTR bstrConfigCommitPath = SysAllocString( L"MACHINE/WEBROOT/APPHOST" );
BSTR bstrSectionName = SysAllocString( L"system.applicationHost/sites" );
BSTR bstrPropertyName = SysAllocString( L"name" );
DWORD dwElementCount = 0;
VARIANT vtValue;
VARIANT vtPropertyName;
vtPropertyName.vt = VT_BSTR;
vtPropertyName.bstrVal = bstrPropertyName;
// Initialize
hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
if ( FAILED( hr ) )
{
printf_s( "ERROR: Unable to initialize\n" );
goto exit;
}
// Create
hr = CoCreateInstance( __uuidof( AppHostAdminManager ), NULL,
CLSCTX_INPROC_SERVER,
__uuidof( IAppHostAdminManager ), (void**) &pMgr );
if( FAILED( hr ) )
{
printf_s( "ERROR: Unable to create an IAppHostAdminManager\n" );
goto exit;
}
// Get the admin section
hr = pMgr->GetAdminSection( bstrSectionName, bstrConfigCommitPath, &pParentElem );
if ( FAILED( hr ) || ( &pParentElem == NULL ) )
{
if ( E_ACCESSDENIED == hr )
{
printf_s( "ERROR: Access to configuration denied.\n" );
printf_s( " Run sample as an administrator.\n" );
}
else
{
printf_s( "ERROR: Unable to get asp configuration section.\n" );
}
goto exit;
}
// Get the site collection
hr = pParentElem->get_Collection( &pElemColl );
if ( FAILED ( hr ) || ( &pElemColl == NULL ) )
{
wprintf_s ( L"ERROR: Unable to access element collection of %s\n", bstrSectionName );
goto exit;
}
// Get the elements
wprintf_s( L"Seaching for elements in %s\n", bstrSectionName );
hr = pElemColl->get_Count( &dwElementCount );
for ( USHORT i = 0; i < dwElementCount; i++ )
{
VARIANT vtItemIndex;
vtItemIndex.vt = VT_I2;
vtItemIndex.iVal = i;
// Add a new section group
hr = pElemColl->get_Item( vtItemIndex, &pElem );
if ( FAILED( hr ) || ( &pElem == NULL ) )
{
wprintf_s( L"ERROR: Unable to find element: %d\n", i );
goto loop_cleanup;
}
// Get the child elements
hr = pElem->get_Properties( &pElemProps );
if ( FAILED( hr ) || ( &pElemProps == NULL ) )
{
printf_s( "ERROR: Unable to access attributes\n" );
goto exit;
}
hr = pElemProps->get_Item( vtPropertyName, &pElemProp );
if ( FAILED( hr ) || ( pElemProp == NULL ) )
{
printf_s( "ERROR: Unable to access attribute\n" );
goto exit;
}
hr = pElemProp->get_Value( &vtValue );
if ( FAILED( hr ) )
{
wprintf_s( L"ERROR: Unable to access attribute value: %s\n", bstrPropertyName );
goto exit;
}
wprintf_s( L"Site name is: %s\n", vtValue.bstrVal );
loop_cleanup:
if ( pElem != NULL )
{
printf_s("\treleasing collection element\n");
pElem->Release();
pElem = NULL;
}
}
exit:
// Exiting / Unwinding
if ( pElemProp != NULL )
{
pElemProp->Release();
pElemProp = NULL;
}
if ( pElemProps != NULL )
{
pElemProps->Release();
pElemProps = NULL;
}
if ( pElem != NULL )
{
pElem->Release();
pElem = NULL;
}
if ( pElemColl != NULL )
{
pElemColl->Release();
pElemColl = NULL;
}
if ( pParentElem != NULL )
{
pParentElem->Release();
pParentElem = NULL;
}
if ( pMgr != NULL )
{
pMgr->Release();
pMgr = NULL;
}
SysFreeString( bstrConfigCommitPath );
SysFreeString( bstrSectionName );
// Uninitialize
CoUninitialize();
return 0;
};
Anforderungen
| type | BESCHREIBUNG |
|---|---|
| Client | – IIS 7.0 unter Windows Vista – IIS 7.5 unter Windows 7 – IIS 8.0 unter Windows 8 – IIS 10.0 auf Windows 10 |
| Server | – IIS 7.0 unter Windows Server 2008 – IIS 7.5 unter Windows Server 2008 R2 – IIS 8.0 unter Windows Server 2012 – IIS 8.5 unter Windows Server 2012 R2 – IIS 10.0 auf Windows Server 2016 |
| Produkt | – IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0 - IIS Express 7.5, IIS Express 8.0, IIS Express 10.0 |
| Header | Ahadmin.h |