### Starting a Web Site using Site.Start (VBScript) Source: https://learn.microsoft.com/en-us/iis/wmi-provider/site-start-method This VBScript example demonstrates how to start a Web site named 'IISWebSite' using the Site.Start method. It includes connecting to the WMI WebAdministration namespace and retrieving the specific site object. ```vbscript ' Connect to the WMI WebAdministration namespace. Set oWebAdmin= GetObject("winmgmts:root\WebAdministration") ' Specify the Web site name. Set oSite= oWebAdmin.Get("Site.Name='IISWebSite'") ' Start the Web site. oSite.Start ``` -------------------------------- ### Run ARR v2 Installer Source: https://learn.microsoft.com/en-us/iis/extensions/installing-application-request-routing-arr/install-application-request-routing-version-2 Execute the downloaded ARR v2 setup executable. Replace '' with 'x86' or 'x64' depending on your system. ```bash ARRv2_ setup_x86.exe ``` ```bash ARRv2_setup_ x64.exe ``` -------------------------------- ### Web Deploy Manifest File Example Source: https://learn.microsoft.com/en-us/iis/publish/using-web-deploy/web-deploy-parameterization Defines providers and their settings for application installation using Web Deploy. ```xml ``` -------------------------------- ### Examples of Getting Help for IIS-Specific Cmdlets Source: https://learn.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-using-the-powershell-help-system These examples demonstrate how to use the Get-Help cmdlet for specific IIS cmdlets like Get-WebConfiguration, Get-WebItemState, and Add-WebConfiguration. ```PowerShell Get-Help Get-WebConfiguration Get-Help Get-WebItemState Get-Help Add-WebConfiguration ``` -------------------------------- ### Install FPSE using msiexec command Source: https://learn.microsoft.com/en-us/iis/publish/frontpage-server-extensions/installing-the-frontpage-server-extensions-on-iis Use this command in an elevated command prompt to start the FPSE installation process when not logged in as the local administrator. ```console msiexec /i \.msi ``` -------------------------------- ### HTTP Module Example using GetApplication Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/iglobalthreadcleanupprovider-getapplication This example demonstrates creating an HTTP module that registers for GL_THREAD_CLEANUP notifications. It retrieves an IHttpApplication interface using GetApplication, then gets the application identifier and logs it to the Event Viewer. ```cpp // The following code example demonstrates how to create an HTTP module that performs the following tasks: // 1. Registers for the GL_THREAD_CLEANUP notification. // 2. Creates a CGlobalModule class that contains an OnGlobalThreadCleanup method. This method performs the following tasks: // 1. Retrieves an `IHttpApplication` interface by using the `GetApplication` method. // 2. Retrieves the application identifier of the current context's application by using the IHttpApplication::GetApplicationId method. // 3. Writes the application identifier information as an event to the application log of the Event Viewer. // 3. Removes the `CGlobalModule` class from memory and then exits. ``` -------------------------------- ### GetApplication Method Example Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/ihttpcontext-getapplication-method This C++ code example demonstrates how to use the `GetApplication` method to retrieve the physical path of the current web application. It shows the steps to get the `IHttpApplication` interface, then its physical path, and finally how to write this path to the HTTP response. ```APIDOC ## GetApplication Method ### Description Retrieves a pointer to the `IHttpApplication` interface for the current request. ### Method Signature ```cpp IHttpApplication * GetApplication( void ); ``` ### Parameters None ### Return Value Returns a pointer to an `IHttpApplication` interface that provides access to application-level information. Returns `NULL` if the application interface is not available. ### Example Usage ```cpp // Retrieve a pointer to the IHttpApplication class. IHttpApplication * pHttpApplication = pHttpContext->GetApplication(); // Retrieve a pointer to the application configuration path. PCWSTR pwszApplicationPhysicalPath = pHttpApplication->GetApplicationPhysicalPath(); // ... (rest of the example code to process and write the path) ``` ``` -------------------------------- ### Create Web Site Example Source: https://learn.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/consuming-the-services Demonstrates creating a website using the CreateWebSite method. Ensure to instantiate the WebProvisioningServiceClient and correctly populate the WebSiteProvisioningRequest object. Handles potential FaultExceptions and general exceptions during the process. ```Console WebProvisioningServiceClient client = new WebProvisioningServiceClient(); try { BindingInfo binding = new BindingInfo(); binding.Protocol ="http"; binding.IPAddress ="*"; //all ip addresses binding.TCPPort = 80; binding.HostHeader ="www.contoso.com"; WebSiteProvisioningRequest request = new WebSiteProvisioningRequest(); request.SiteName ="www.contoso.com"; request.DomainName =string.Empty; request.UserName ="Testuser"; request.Password ="pass@word1"; request.ContentPath = @"c:\\contents\"; request.UserDefaultContentStructure = false; request.PhysicalRootPath = @"c:\\contents\\www.contoso.com"; request.LogPath = @"c:\\contents\\www.contoso.com\\logs"; request.FaultRequestsLoggingPath = c:\\contents\\www.contoso.com\\logs\\FailedRequestLogs"; request.Binding = binding; request.CreateNewApplicationPool = true; request.ApplicationPoolName = "TestAppPool"; request.StartSite = true; request.SiteId = 0; if (client.CreateWebSite(request)) this.lblResult.Text = "Web Site: " + request.SiteName + " has been successfully created."; client.Close(); } catch (FaultException ex) { this.lblResult.Text = "FaultException: Hosting service fault while doing " + ex.Detail.Operation + ". Error: " + ex.Detail.ErrorMessage; client.Abort(); } catch (FaultException ex) { this.lblResult.Text = "Add Web Site Failed with unknown faultexception: " + e.GetType().Name + " - " + ex.Message; client.Abort(); } catch (Exception ex) { this.lblResult.Text = "Failed with exception: " + ex.GetType().Name + " - " + ex.Message; client.Abort(); } ``` -------------------------------- ### IIS Setup Log Entry Example Source: https://learn.microsoft.com/en-us/iis/troubleshoot This log entry shows a typical 'FAIL' error during IIS 7.0 component-based setup, indicating a failure in installing the FTPServer component with a specific error code. ```log [11/12/2010 19:48:13] [ ***** IIS 7.0 Component Based Setup ***** ] [11/12/2010 19:48:13] "C:\Windows\System32\inetsrv\iissetup.exe" /install FTPServer [11/12/2010 19:48:13] < !!FAIL!! > METABASE_UTIL::InstallFtpMetabaseEntries result=0x800708c5 [11/12/2010 19:48:13] < !!FAIL!! > Install of component FTPServer result=0x800708c5 [11/12/2010 19:48:13] < !!FAIL!! > COMPONENT::ExecuteCommand result=0x800708c5 [11/12/2010 19:48:13] [ End of IIS 7.0 Component Based Setup ] ``` -------------------------------- ### Run First Site in Default Configuration Source: https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line Start the first website listed in the default applicationhost.config file. ```bash iisexpress ``` -------------------------------- ### Start IIS Services After ARR Installation Source: https://learn.microsoft.com/en-us/iis/extensions/installing-application-request-routing-arr/install-application-request-routing-version-2 Start the Web Server (WAS), Windows Process Activation Service (WMSVC), and World Wide Web Publishing Service (W3SVC) after the ARR installation is complete. ```bash net start was ``` ```bash net start wmsvc ``` ```bash net start w3svc ``` -------------------------------- ### Run SetupSiteForPublish Script Source: https://learn.microsoft.com/en-us/iis/publish/using-web-deploy/powershell-scripts-for-automating-web-deploy-setup Executes the SetupSiteForPublish.ps1 script without arguments to create a default website and user for non-admin publishing. This script generates a WDeploy.PublishSettings file on the desktop. ```powershell .\SetupSiteForPublish.ps1 ``` -------------------------------- ### Start PowerShell Console Source: https://learn.microsoft.com/en-us/iis/web-hosting/microsoft-web-farm-framework-20-for-iis-7/web-farm-framework-20-for-iis-cmdlets-for-windows-powershell This command starts the PowerShell console on the controller server. Ensure Windows PowerShell is installed. ```PowerShell PowerShell ``` -------------------------------- ### Start IIS Services Source: https://learn.microsoft.com/en-us/iis/extensions/installing-application-request-routing-arr/install-application-request-routing Start the Windows Activation Service (WAS) and the Web Management Service (WMSVC) after the ARR installation is complete. ```bash net start was ``` ```bash net start wmsvc ``` -------------------------------- ### Get Feature URI for Uninstall Source: https://learn.microsoft.com/en-us/iis-administration/api/installing-features Before uninstalling a feature, retrieve its URI by sending a GET request to the /api/webserver endpoint. This example shows how to get the URI for the default document feature. ```HTTP GET /api/webserver ``` ```JSON { "id": "{id}", "_links": { ... "default_document": { "href": "/api/webserver/default-documents/{def-doc-id}" } } } ``` -------------------------------- ### Get HTTP Errors Section Example Source: https://learn.microsoft.com/en-us/iis/wmi-provider/configuredobject-getsection-method This example demonstrates how to retrieve the HTTP errors section for the default Web site and display its properties. It connects to the WMI WebAdministration namespace, gets the default Web site, and then uses GetSection to retrieve the HttpErrorsSection. ```vbscript ' Connect to the WMI WebAdministration namespace. Set oWebAdmin = GetObject("winmgmts:root\WebAdministration") ' Get the default Web site. Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'") ' Get the HTTP errors section by using the GetSection method. oSite.GetSection "HttpErrorsSection", oSection ' Display a heading. WScript.Echo "==============================" WScript.Echo "Http Errors Section Properties" WScript.Echo "==============================" ' Display the HttpErrorsSection non-array properties. For Each vProp In oSection.Properties_ If (vProp.Name <> "HttpErrors") And _ (vProp.Name <> "SectionInformation") Then WScript.Echo vProp.Name & ": " & vProp.Value End If Next WScript.Echo ' Display the HttpErrorsSection SectionInformation properties. WScript.Echo "HttpErrorsSection.SectionInformation" WScript.Echo "------------------------------------" For Each vProp In oSection.SectionInformation.Properties_ WScript.Echo vProp.Name & ": " & vProp.Value Next WScript.Echo ' Display the contents of the HttpErrors array property. WScript.Echo "HttpErrorsSection.HttpErrors" WScript.Echo "----------------------------" For Each oHttpErrorElement In oSection.HttpErrors For Each vProp In oHttpErrorElement.Properties_ WScript.Echo vProp.Name & ": " & vProp.Value Next WScript.Echo Next ``` -------------------------------- ### Site.Start Method Source: https://learn.microsoft.com/en-us/iis/wmi-provider/site-start-method Starts an existing Web site. This method takes no parameters and returns no value. ```APIDOC ## Site.Start Method ### Description Starts an existing Web site. ### Method This method takes no parameters. ### Return Value This method does not return a value. ### Remarks This method is new to the IIS 7 WMI provider and has no counterpart in IIS 6.0. ### Example ```vbscript ' Connect to the WMI WebAdministration namespace. Set oWebAdmin= GetObject("winmgmts:root\WebAdministration") ' Specify the Web site name. Set oSite= oWebAdmin.Get("Site.Name='IISWebSite'") ' Start the Web site. oSite.Start ``` To check the status of the Web site after you call the `Start` method, use the GetState method. ``` -------------------------------- ### IHttpContext::GetSite Method Example Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/ihttpcontext-getsite-method This example demonstrates how to use the GetSite method to retrieve the IHttpSite interface and then get the site name. ```APIDOC ## IHttpContext::GetSite ### Description Retrieves an `IHttpSite` interface for the current Web site. ### Method `IHttpSite* GetSite(void);` ### Parameters This method takes no parameters. ### Return Value Returns a pointer to an `IHttpSite` interface that represents the Web site for the current request. The caller is responsible for releasing this interface when it is no longer needed. ### Example ```cpp // Assuming 'pHttpContext' is a pointer to an IHttpContext interface IHttpSite* pHttpSite = pHttpContext->GetSite(); if (pHttpSite != NULL) { // Get the site name PCWSTR siteName = pHttpSite->GetSiteName(); // Use the siteName... // Release the IHttpSite interface when done pHttpSite->Release(); } ``` ``` -------------------------------- ### Create a New Web Site (VBScript Example) Source: https://learn.microsoft.com/en-us/iis/wmi-provider/site-create-method Use this VBScript example to create a new website. It connects to the WMI WebAdministration namespace, specifies site details, creates a BindingElement, and then calls the Create method on the Site definition. ```vbs ' Connect to the WMI WebAdministration namespace. Set oWebAdmin = GetObject("winmgmts:root\WebAdministration") ' Specify a name and physical path for the new Web site. SiteName = "SampleSite" PhysicalPath = "C:\inetpub\wwwroot" ' Create a Bindings object by using the WMI SpawnInstance_ method. Set SiteBinding = oWebAdmin.Get("BindingElement").SpawnInstance_ SiteBinding.BindingInformation = "*:80:www.SampleSite.com" SiteBinding.Protocol = "http" BindingsArray = array(SiteBinding) ' Get the site object definition Set SiteDefinition = oWebAdmin.Get("Site") ' Pass the required parameters to the Create method on the Site ' definition to create the site. SiteDefinition.Create SiteName, BindingsArray, PhysicalPath ``` -------------------------------- ### Check if a Feature Is Installed Source: https://learn.microsoft.com/en-us/iis-administration/api/installing-features Determines if an IIS feature is installed by sending a GET request to its API endpoint. A 200 OK response indicates the feature is installed, while a 404 Not Found response signifies it is not. ```APIDOC ## GET /api/webserver/default-documents?scope= ### Description Checks if the default document feature is installed on the web server. ### Method GET ### Endpoint /api/webserver/default-documents?scope= ### Parameters #### Query Parameters - **scope** (string) - Required - Specifies the scope for the request. An empty value targets the web server scope. ### Response #### Success Response (200 OK) - **id** (string) - The unique identifier of the feature. - **enabled** (string) - Indicates if the feature is enabled ('true' or 'false'). - **scope** (string) - The scope of the feature configuration. - **metadata** (object) - Contains metadata about the feature's local status and locking. - **is_local** (string) - Indicates if the feature is locally installed. - **is_locked** (string) - Indicates if the feature is locked. - **override_mode** (string) - The override mode setting. - **override_mode_effective** (string) - The effective override mode. - **website** (null) - This field is null when targeting the web server scope. #### Error Response (404 Not Found) - **title** (string) - "Not found" - **detail** (string) - "IIS feature not installed" - **name** (string) - The name of the feature (e.g., "Default Document"). - **status** (string) - "404" ``` -------------------------------- ### View Site Addition Parameters Source: https://learn.microsoft.com/en-us/iis/get-started/getting-started-with-iis/getting-started-with-appcmdexe Use the command help syntax with '/?' to see required parameters for adding a new site. ```bash %systemroot%\system32\inetsrv\APPCMD add site /? ``` -------------------------------- ### GetUniqueConfigPath Example Input/Output Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/iapphostconfigmanager-getuniqueconfigpath-method Illustrates example input and output values for the GetUniqueConfigPath method, assuming configuration is set at MACHINE, MACHINE/WEBROOT, and MACHINE/WEBROOT/Site1 levels. ```text Input values for `bstrConfigPath` | Output values for `pbstrUniquePath` ---|--- MACHINE | MACHINE MACHINE/WEBROOT/Site1 | MACHINE/WEBROOT/Site1 MACHINE/WEBROOT/Site1/HelloWorldApp | MACHINE/WEBROOT/Site1 ``` -------------------------------- ### Check if Default Document Feature is Installed (Not Found) Source: https://learn.microsoft.com/en-us/iis-administration/api/installing-features Send a GET request to the feature's API endpoint with an empty scope to check if it's installed. A 404 response indicates the feature is not installed. ```HTTP GET /api/webserver/default-documents?scope= ``` ```JSON { "title": "Not found", "detail": "IIS feature not installed", "name": "Default Document", "status": "404" } ``` -------------------------------- ### AppCmd Output: List of Applications Source: https://learn.microsoft.com/en-us/iis/get-started/getting-started-with-iis/getting-started-with-appcmdexe This is an example output showing the applications configured on the server, including their names and associated application pools. ```text APP "Default Web Site/" (applicationPool:DefaultAppPool) APP "MySite/" (applicationPool:DefaultAppPool) APP "MySite/app1" (applicationPool:DefaultAppPool) ``` -------------------------------- ### Get Example Usage for a Cmdlet Source: https://learn.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-using-the-task-based-cmdlets-of-the-iis-powershell-snap-in Displays example commands demonstrating how to use a specific cmdlet. This is ideal for quickly learning practical applications of the cmdlet. ```PowerShell get-help New-Website -example ``` -------------------------------- ### HTTP Module Example using GetApplication Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/ihttpapplicationprovider-getapplication-method This C++ example demonstrates creating an HTTP module that retrieves the application's physical path using IHttpApplication::GetApplication and logs it to the Event Viewer. ```cpp // The following code example demonstrates how to create an HTTP module that performs the following tasks: // 1. Registers for the GL_APPLICATION_START notification. // 2. Creates a CGlobalModule class that contains an OnGlobalApplicationStart method. This method performs the following tasks: // 1. Retrieves an IHttpApplication interface by using the GetApplication method. // 2. Retrieves the physical path of the current context's application by using the IHttpApplication::GetApplicationPhysicalPath method. // 3. Writes the physical path information as an event to the application log of the Event Viewer. // 3. Removes the CGlobalModule class from memory and then exits. ``` -------------------------------- ### Install Default Document Feature Source: https://learn.microsoft.com/en-us/iis-administration/api/installing-features Install an IIS feature by sending a POST request to its endpoint. This example shows installing the default document feature, which returns a 201 CREATED status and the feature's settings. ```HTTP POST /api/webserver/default-documents ``` ```JSON { "id": "{id}", "enabled": "true", "scope": "", "metadata": { "is_local": "true", "is_locked": "false", "override_mode": "allow", "override_mode_effective": "allow" }, "website": null } ``` -------------------------------- ### Start WCAT Client Source: https://learn.microsoft.com/en-us/iis/manage/managing-performance-settings/walkthrough-iis-output-caching Launch the WCAT client to begin performance testing against the specified server. ```command-line "%programfiles%\IIS Resources\WCAT Client\wcclient.exe" localhost ``` -------------------------------- ### Get and Set ColumnWidth Property in JavaScript Source: https://learn.microsoft.com/en-us/iis/extensions/database-manager-reference/querycolumnmetadata-columnwidth-property-microsoft-web-management-databasemanager This example shows the syntax for getting and setting the ColumnWidth property in a JavaScript-like syntax, indicating the expected data type for the value. ```javascript function get ColumnWidth () : long function set ColumnWidth (value : long) ``` -------------------------------- ### Install Web Deploy MSI Source: https://learn.microsoft.com/en-us/iis/publish/using-web-deploy/microsoft-web-deploy-v2-readme Run the MSI installer for Web Deploy. Ensure you have the correct path to the MSI file. ```console msiexec /I msiexec /I ``` -------------------------------- ### Example Usage of IAppHostChildElementCollection Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/iapphostchildelementcollection-interface This C++ code example demonstrates how to use the IAppHostChildElementCollection interface to retrieve and list all child elements under a specified configuration section, such as 'system.webServer/asp'. It shows the process of initializing COM, obtaining an admin manager, getting the parent element, accessing its child elements collection, and iterating through them to get their names. ```APIDOC ## Example The following code example lists all child elements under the `system.webServer/asp` configuration section for the MACHINE/WEBROOT/APPHOST path. C++ Copy ```cpp #pragma once #include #include #include int main() { IAppHostAdminManager * pMgr = NULL; IAppHostElement * pParentElem = NULL; IAppHostChildElementCollection * pChildElems = NULL; IAppHostElement * pChildElem = NULL; HRESULT hr = S_OK; BSTR bstrSectionName = SysAllocString( L"system.webServer/asp" ); BSTR bstrChildElemName = NULL; DWORD dwElementCount = 0; // Initialize hr = CoInitializeEx( NULL, COINIT_MULTITHREADED ); if ( FAILED( hr ) ) { printf_s( "ERROR: Unable to initialize\n" ); goto exit; } // Create an admin manager 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 wprintf_s( L"Getting %s\n", bstrSectionName ); hr = pMgr->GetAdminSection( bstrSectionName, NULL, &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 child elements wprintf_s( L"Getting child elements\n" ); hr = pParentElem->get_ChildElements( &pChildElems ); if ( FAILED( hr ) || ( &pChildElems == NULL ) ) { wprintf_s( L"ERROR: Unable to access child elements of %s\n", bstrSectionName ); goto exit; } // Loop through child elements wprintf_s( L"Seaching for child elements of %s\n", bstrSectionName ); hr = pChildElems->get_Count( &dwElementCount ); for( USHORT i = 0; i < dwElementCount; i++ ) { VARIANT vtItemIndex; vtItemIndex.vt = VT_I2; vtItemIndex.iVal = i; // Get the section group hr = pChildElems->get_Item( vtItemIndex, &pChildElem ); if ( FAILED( hr ) || ( &pChildElem == NULL ) ) { wprintf_s( L"ERROR: Unable to find child element: %d\n", i ); goto loop_cleanup; } // Get the name hr = pChildElem->get_Name ( &bstrChildElemName ); if ( FAILED( hr ) ) { wprintf_s( L"ERROR: Unable to get child element name.\n" ); goto loop_cleanup; } wprintf_s( L"\tChild element found: %s\n", bstrChildElemName ); loop_cleanup: if ( pChildElem != NULL ) { pChildElem->Release(); pChildElem = NULL; } SysFreeString( bstrChildElemName ); } exit: // Exiting / Unwinding if ( pChildElems != NULL ) { pChildElems->Release(); pChildElems = NULL; } if ( pParentElem != NULL ) { pParentElem->Release(); pParentElem = NULL; } if ( pMgr != NULL ) { pMgr->Release(); pMgr = NULL; } SysFreeString( bstrChildElemName ); SysFreeString( bstrSectionName ); // Uninitialize CoUninitialize(); return 0; }; ``` ``` -------------------------------- ### Configure Application Initialization with VBScript Source: https://learn.microsoft.com/en-us/iis/configuration/system.webserver/applicationinitialization/add This VBScript example demonstrates how to configure IIS application initialization settings and add initialization pages using the WritableAdminManager object. ```vbscript Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager") adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST" Set applicationInitializationSection = adminManager.GetAdminSection("system.webServer/applicationInitialization", "MACHINE/WEBROOT/APPHOST/Default Web Site") applicationInitializationSection.Properties.Item("remapManagedRequestsTo").Value = "HelloJoe.htm" applicationInitializationSection.Properties.Item("skipManagedModules").Value = true applicationInitializationSection.Properties.Item("doAppInitAfterRestart").Value = true Set applicationInitializationCollection = applicationInitializationSection.Collection Set addElement = applicationInitializationCollection.CreateNewElement("add") addElement.Properties.Item("initializationPage").Value = "JoesSite.htm" addElement.Properties.Item("hostName").Value = "JoesHost" applicationInitializationCollection.AddElement(addElement) adminManager.CommitChanges() ``` -------------------------------- ### Synchronize IIS Site from Package (WhatIf) Source: https://learn.microsoft.com/en-us/iis/publish/using-web-deploy/synchronize-iis Simulate synchronizing an IIS site from a package file to the destination server using `msdeploy` with the -whatif flag. The output is logged to msdeploysync.log. ```console msdeploy -verb:sync -source:package=c:\site1.zip -dest:apphostconfig="Default Web Site" -whatif > msdeploysync.log ``` -------------------------------- ### IHttpContext::GetScriptMap Method Example Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/iscriptmapinfo-getresourcetype-method This example demonstrates how to use the IHttpContext::GetScriptMap method to retrieve an IScriptMapInfo interface and then use its GetResourceType method to get the resource type for the current request. ```APIDOC ## IHttpContext::GetScriptMap ### Description Retrieves a pointer to an IScriptMapInfo interface for the current request. ### Method This is a method of the `IHttpContext` interface. ### Parameters None ### Return Value Returns a pointer to an `IScriptMapInfo` interface. The caller is responsible for releasing this interface. ### Example ```cpp // Assume httpContext is a valid IHttpContext pointer IScriptMapInfo* scriptMapInfo = httpContext->GetScriptMap(); if (scriptMapInfo) { // Use scriptMapInfo to get resource type or other script map information // ... scriptMapInfo->Release(); // Release the interface when done } ``` ``` -------------------------------- ### IFileKey::GetPath Output Example Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/ifilekey-getpath-method This shows an example of the data logged to the Event Viewer when IFileKey::GetPath is called. ```text IFileKey::GetPath: C:\INETPUB\WWWROOT\DEFAULT.HTM ``` -------------------------------- ### Get Help for Built-in Cmdlets in IIS Namespace Source: https://learn.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-using-the-powershell-help-system Use this command to get detailed information on how built-in cmdlets function within the IIS namespace. It displays syntax, required parameters, and examples. ```PowerShell get-help WebAdministration | more ``` -------------------------------- ### Retrieve Current Execution Statistics Source: https://learn.microsoft.com/en-us/iis/web-development-reference/native-code-api-reference/ihttpcontext-getcurrentexecutionstats-method Call this method to get the current notification type, its start time, the current module name, its start time, and asynchronous notification details. All parameters are output pointers. ```cpp virtual HRESULT GetCurrentExecutionStats( DWORD* pdwNotification, DWORD* pdwNotificationStartTickCount = NULL, PCWSTR* ppszModule = NULL, DWORD* pdwModuleStartTickCount = NULL, DWORD* pdwAsyncNotification = NULL, DWORD* pdwAsyncNotificationStartTickCount = NULL ) const = 0; ``` -------------------------------- ### Start IIS Site Source: https://learn.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-run-time-data Start an IIS website using the Start-WebItem cmdlet. ```PowerShell PS IIS:\Sites> Start-WebItem DemoSite PS IIS:\sites> Get-WebItemState IIS:\sites\DemoSite Started ``` -------------------------------- ### Start Windows PowerShell on Server Core Source: https://learn.microsoft.com/en-us/iis/install/installing-iis-7/install-and-configure-iis-on-server-core Launch Windows PowerShell from its installation directory on Server Core. ```batch \windows\system32\WindowsPowerShell\v1.0\powershell.exe ``` -------------------------------- ### View Site Setting Parameters Source: https://learn.microsoft.com/en-us/iis/get-started/getting-started-with-iis/getting-started-with-appcmdexe Use the command help syntax with '/?' to view settable properties for a specific object like a site. ```bash %systemroot%\system32\inetsrv\APPCMD set site "Default Web Site" /? ``` -------------------------------- ### C# Sample for Creating a Website Source: https://learn.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/consuming-the-services A comprehensive C# code sample demonstrating how to instantiate the WebProvisioningServiceClient, configure a WebSiteProvisioningRequest object with various properties, and call the CreateWebSite method. Includes error handling for different exception types. ```APIDOC ## C# Sample for Creating a Website ### Description This sample demonstrates the creation of a website using the service. It shows how to instantiate the **WebProvisioningServiceClient** proxy, configure the **WebSiteProvisioningRequest** object, and handle potential exceptions during the process. ### Code Example ```csharp WebProvisioningServiceClient client = new WebProvisioningServiceClient(); try { BindingInfo binding = new BindingInfo(); binding.Protocol = "http"; binding.IPAddress = "*"; //all ip addresses binding.TCPPort = 80; binding.HostHeader = "www.contoso.com"; WebSiteProvisioningRequest request = new WebSiteProvisioningRequest(); request.SiteName = "www.contoso.com"; request.DomainName = string.Empty; request.UserName = "Testuser"; request.Password = "pass@word1"; request.ContentPath = @"c:\contents\"; request.UserDefaultContentStructure = false; request.PhysicalRootPath = @"c:\contents\www.contoso.com"; request.LogPath = @"c:\contents\www.contoso.com\logs"; request.FaultRequestsLoggingPath = @"c:\contents\www.contoso.com\logs\FailedRequestLogs"; request.Binding = binding; request.CreateNewApplicationPool = true; request.ApplicationPoolName = "TestAppPool"; request.StartSite = true; request.SiteId = 0; if (client.CreateWebSite(request)) this.lblResult.Text = "Web Site: " + request.SiteName + " has been successfully created."; client.Close(); } catch (FaultException ex) { this.lblResult.Text = "FaultException: Hosting service fault while doing " + ex.Detail.Operation + ". Error: " + ex.Detail.ErrorMessage; client.Abort(); } catch (FaultException ex) { this.lblResult.Text = "Add Web Site Failed with unknown faultexception: " + e.GetType().Name + " - " + ex.Message; client.Abort(); } catch (Exception ex) { this.lblResult.Text = "Failed with exception: " + ex.GetType().Name + " - " + ex.Message; client.Abort(); } ``` ``` -------------------------------- ### Example Usage Source: https://learn.microsoft.com/en-us/iis/wmi-provider/mimemapelement-class This VBScript example demonstrates how to connect to the WMI WebAdministration namespace and list file extensions and their associated MIME types from the ApplicationHost.config file. ```APIDOC ## Example ```vbscript ' Connect to the WMI WebAdministration namespace. Set oWebAdmin = GetObject("winmgmts:root\WebAdministration") ' Get the section in ApplicationHost.config. Set oSection = oWebAdmin.Get( _ "StaticContentSection.Path='MACHINE/WEBROOT/APPHOST',Location=''") ' List the MIME maps by using the StaticContent property of the StaticContentSection class. For Each oMimeMapElement In oSection.StaticContent WScript.Echo "File Extension: " & oMimeMapElement.FileExtension WScript.Echo "Mime Type: " & oMimeMapElement.MimeType WScript.Echo Next ``` ``` -------------------------------- ### Start IIS Services Source: https://learn.microsoft.com/en-us/iis/extensions/iis-compression/iis-compression-overview After installation, restart the World Wide Web Publishing Service (W3SVC) to apply the changes. ```powershell net start w3svc ``` -------------------------------- ### Start FTP Site with VB.NET Source: https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/ftpserver/start Use the Microsoft.Web.Administration library to start an FTP site. Ensure the necessary imports are included. ```vb.net Imports System Imports System.Text Imports Microsoft.Web.Administration Module Sample Sub Main() Dim serverManager As ServerManager = New ServerManager Dim config As Configuration = serverManager.GetApplicationHostConfiguration ' Retrieve the sites collection. Dim sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites") Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection ' Locate a specific site. Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "mySite") If (siteElement Is Nothing) Then Throw New InvalidOperationException("Element not found!") End If ' Create an object for the ftpServer element. Dim ftpServerElement As ConfigurationElement = siteElement.GetChildElement("ftpServer") ' Create an instance of the FlushLog method. Dim Start As ConfigurationMethodInstance = ftpServerElement.Methods("Start").CreateInstance() ' Execute the method to start the FTP site. Start.Execute() End Sub Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement For Each element As ConfigurationElement In collection If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then Dim matches As Boolean = True Dim i As Integer For i = 0 To keyValues.Length - 1 Step 2 Dim o As Object = element.GetAttributeValue(keyValues(i)) Dim value As String = Nothing If (Not (o) Is Nothing) Then value = o.ToString End If If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then matches = False Exit For End If Next If matches Then Return element End If End If Next Return Nothing End Function End Module ``` -------------------------------- ### Create Web Site for Specific Application Pool Source: https://learn.microsoft.com/en-us/iis-administration/api/sites This example shows how to create a web site and assign it to a specific application pool by providing the application pool's ID. ```json { "name": "Demonstration Site", "physical_path": "C:\\inetpub\\wwwroot\\DemonstrationSite", "bindings": [ { "protocol": "HTTP", "port": "8081", "ip_address": * } ], "application_pool": { "id": {application_pool_id} } } ``` -------------------------------- ### Get IIS Site State Source: https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/iisadministration-powershell-cmdlets This example shows how to retrieve the state of a specific IIS website. It first gets the sites configuration section, then accesses a specific site by its name, and finally retrieves the value of its 'State' attribute. ```powershell PS:>$ConfigSection = Get-IISConfigSection -SectionPath "system.applicationHost/sites" PS:>Get-IISConfigCollection $configSection | Get-IISConfigCollectionElement -ConfigAttribute @{"Name"="Default Web Site"} | Get-IISConfigAttributeValue -AttributeName "State" ``` -------------------------------- ### Reviewing CBS Log for IIS Setup Failures Source: https://learn.microsoft.com/en-us/iis/troubleshoot Examine CBS log entries to identify errors during IIS setup, specifically looking for 'Failed execution of queue item Installer: Generic Command' and associated HRESULTs. ```log 2010-07-08 14:04:08, Info CSI 00000047 Calling generic command executable (sequence 2): [40]"C:\Windows\System32\inetsrv\iissetup.exe" CmdLine: [151]""C:\Windows\System32\inetsrv\iissetup.exe" /launch C:\Windows\System32\inetsrv\appcmd.exe reset config -section:system.applicationHost/listenerAdapters" 2010-07-08 14:04:08, Error CSI 00000048 (F) Done with generic command 2; CreateProcess returned 0, CPAW returned S_OK Process exit code 16386 (0x00004002) resulted in success? FALSE Process output: [l:22 [22]"Failed = 0x80004002"][gle=0x80004005] 2010-07-08 14:04:09, Info CSI 00000051@2010/7/8:18:04:09.688 CSI Advanced installer perf trace:CSIPERF:AIDONE; {81a34a10-4256-436a-89d6-794b97ca407c};Microsoft-Windows-IIS-SharedLibraries, Version = 6.1.7600.16385, pA = PROCESSOR_ARCHITECTURE_AMD64 (9), Culture neutral, VersionScope = 1 nonSxS, PublicKeyToken = {l:8 b:31bf3856ad364e35}, Type neutral, TypeName neutral, PublicKey Neutral;6148228 2010-07-08 14:04:09, Error [0x018007] CSI 00000052 (F) Failed execution of queue item Installer: Generic Command ({81a34a10-4256-436a-89d6-794b97ca407c}) with HRESULT HRESULT_FROM_WIN32(14109). Failure will not be ignored: A rollback will be initiated after all the operations in the installer queue are completed; installer is reliable (2)[gle=0x80004005] 2010-07-08 14:04:10, Info CSI 00000053 End executing advanced installer (sequence 75) Completion status: HRESULT_FROM_WIN32(ERROR_ADVANCED_INSTALLER_FAILED) ``` -------------------------------- ### Start Website Using Custom Configuration Source: https://learn.microsoft.com/en-us/iis/extensions/introduction-to-iis-express/iis-80-express-readme Launch IIS Express and specify a custom configuration file and site name to start a website. This is used after configuring the website using AppCmd. ```console iisexpress.exe /config:C:\Temp\IISExpress\config\ApplicationHost.config /site:www.fabrikam.com ``` -------------------------------- ### Perform Web Deploy Sync using a Package Source: https://learn.microsoft.com/en-us/iis/publish/using-web-deploy/migrate-a-web-site-from-iis-60-to-iis-7-or-above Execute the synchronization command to migrate the website from the package file to the destination IIS server. Ensure you have run the '-whatif' command first. ```console msdeploy -verb:sync -source:package=c:\Site1.zip -dest:metakey=lm/w3svc/1 > WebDeploySync.log ``` -------------------------------- ### Example: Creating a Virtual Directory (VBScript) Source: https://learn.microsoft.com/en-us/iis/wmi-provider/virtualdirectory-create-method This example demonstrates how to create a virtual directory named 'MyVDir' under the 'MyApp' application on the default Web site using VBScript. Ensure you have the necessary authorization to access the WebAdministration namespace. ```vbscript ' Connect to the WebAdministration namespace. Set oWebAdmin = GetObject("winmgmts:root\WebAdministration") ' Define the parameters. strVDirPath = "/MyVDir" strAppPath = "/MyApp" strPhysicalPath = "C:\inetpub\MyVDirFiles" strSiteName = "Default Web Site" ' Create the new virtual directory. oWebAdmin.Get("VirtualDirectory").Create _ strVDirPath, strAppPath, strPhysicalPath, strSiteName ```