none
Creating Virtual Directory in IIS RRS feed

  • Question

  • I am working in installer. I need to create one application/Virtual Directory under my own "MySite" . it is not under "Default Web Site". following are code using for same..But I am unable to create. My requirement is as below in IIS.

    sites

           MySite

                TestApp

                     reports

          Default Web Site.

               asp-net

    My requirement is to create TestApp entry and Virtual directory for this under MySite. I am able to create under Default Web Site but unable to create under MySite. Can anybody please suggest ?

    physicalPath = "AM\\MH"

    virtualpath = "TestApp"

    altVirtualPath = "reports"

    HRESULT CreateIIS7VirtualDirectory(BSTR physicalPath, BSTR virtualPath, BSTR altVirtualPath)
    {
    CComPtr<IAppHostWritableAdminManager> adminManager;
    HRESULT hr = adminManager.CoCreateInstance(__uuidof(AppHostWritableAdminManager));


    if(FAILED(hr))
    return hr;

    CComBSTR sitesSection("system.applicationHost/sites");
    CComBSTR path("MACHINE/WEBROOT/APPHOST/MySite");

    CComPtr<IAppHostElement> sitesElement;
    hr = adminManager->GetAdminSection(sitesSection, path, &sitesElement);

    CComPtr<IAppHostElement> siteElement;
    hr = GetSiteElement(sitesElement, siteElement);

    CComPtr<IAppHostElementCollection> applications;
    hr = siteElement->get_Collection(&applications);

    CComPtr<IAppHostElement> application;
    hr = GetApplicationElement(virtualPath, applications, application);

    hr = SetApplicationVirtualDirectory(application, physicalPath, CComBSTR("/"));

    SetApplicationVirtualDirectory(application, physicalPath, altVirtualPath);

    hr = adminManager->CommitChanges();

    SetApplicationPermissions(virtualPath);

    return S_OK;
    }

    Friday, February 28, 2020 9:53 AM

All replies

  • Hi,

    Thank you for posting here.

    This forum is about c++ development. According to your issue , I suggest you should ask it in the IIS forum. And this thread will be moved to Off-Topic Posts.

    Best Regards,

    Jeanine Zhang
    Monday, March 2, 2020 1:44 AM