Quantcast
Channel: Configuration & Scripting
Viewing all articles
Browse latest Browse all 780

Creating a Virtual Directory

$
0
0

Hi there,

I have created an installer type app to configure my IIS server and all is working fine apart from creating a virtual directory:

I have created this function

HRESULT CreateVirtualDirectory(IAppHostWritableAdminManager* spAppHostAdminManager, IAppHostElement* pWebsite, LPCTSTR lpszApplication, LPCTSTR lpszVirtualDirectory, LPCTSTR lpszPhysicalPath)
{
    //Get the / elemement
    HRESULT hrOut = E_FAIL;
    bool bCreatedDirectory = false;
    IAppHostElementCollection* pApplications = NULL;
    hrOut = pWebsite->get_Collection(&pApplications);
    if (SUCCEEDED(hrOut))
    {
        DWORD cApplications;
        hrOut = pApplications->get_Count(&cApplications);
        if (SUCCEEDED(hrOut))
        {
            VARIANT vtItem;
            VariantInit(&vtItem);
            V_VT(&vtItem) = VT_I4;
            hrOut = S_FALSE;
            for (DWORD iApplication = 0; (iApplication < cApplications) && (!bCreatedDirectory); iApplication++)
            {
                V_I4(&vtItem) = iApplication;
                IAppHostElement* pApplication = NULL;
                hrOut = pApplications->get_Item(vtItem, &pApplication);
                if (SUCCEEDED(hrOut))
                {
                    IAppHostProperty* pProperty = NULL;
                    IAppHostElementSchema* pThisSchema = NULL;
                    hrOut = pApplication->GetPropertyByName(L"path", &pProperty);
                    if (SUCCEEDED(hrOut))
                    {
                        BSTR bstrPath = NULL;
                        hrOut = pProperty->get_StringValue(&bstrPath);
                        if (SUCCEEDED(hrOut))
                        {
                            if (wcscmp(lpszApplication, bstrPath) == 0)
                            {
                                //Now add the virtual directory
                                IAppHostElementCollection* iCollection = NULL;
                                hrOut = pApplication->get_Collection(&iCollection);
                                if (SUCCEEDED(hrOut))
                                {
                                    IAppHostElement* iNewElement = NULL;
                                    hrOut = iCollection->CreateNewElement(L"virtualDirectory", &iNewElement);
                                    if (SUCCEEDED(hrOut))
                                    {
                                        IAppHostPropertyCollection* iProperties = NULL;
                                        hrOut = iNewElement->get_Properties(&iProperties);
                                        if (SUCCEEDED(hrOut))
                                        {
                                            SetElementProperty(iProperties, _T("path"), lpszVirtualDirectory);
                                            SetElementProperty(iProperties, _T("physicalPath"),lpszPhysicalPath);
                                            iProperties->Release();
                                        }
                                        hrOut = iCollection->AddElement(iNewElement);
                                        bCreatedDirectory = true;
                                        iNewElement->Release();
                                    }
                                    iCollection->Release();
                                }
                            }
                        }
                        pProperty->Release();
                    }
                    pApplication->Release();
                }
            }
        }
        pApplications->Release();
    }
    return hrOut;
}



and call it with :

IAppHostWritableAdminManager* spAppHostAdminManager set

IAppHostElement* pWebsite set to the 'Default Web Site' object.

LPCTSTR lpszApplicatio set to "

LPCTSTR lpszVirtualDirectory,Set to a / prefixed string

LPCTSTR lpszPhysicalPath set to an absolute path with no / suffix

All the methods return S_OK

I call HRESULT hr = spAppHostAdminManager->put_CommitPath(L"MACHINE/WEBROOT/APPHOST"); ahead of the function

and

spAppHostAdminManager->CommitChanges();  after it.

I am making chages to the Schema, Modules, Virtual Directory on MACHINE/WEBROOT/APPHOST and Web.Config on the Default Web Site

Everything else works?

How can I debug this - is there any logging I can look at?

Thanks

Mark


Viewing all articles
Browse latest Browse all 780

Latest Images

Trending Articles



Latest Images