WebAdministrationDsc icon indicating copy to clipboard operation
WebAdministrationDsc copied to clipboard

xWebVirtualDirectory Fails to create a virtual directory if it already exists

Open PraveenKalavai opened this issue 7 years ago • 4 comments

xWebVirtualDirectory Services { Name = "Services" Website = $Node.WebsiteName WebApplication = $WebApplication PhysicalPath = "F:\docs\tfs" Ensure = "Present" DependsOn = '[xWebsite]NewWebSite' }

Desired Behavior : The resource should detect the virtual directory exists, and skip it.

*Actual Behavior: It attempts to create the virtual directory, and throws an error saying to use the 'force' parameter.

Error : VERBOSE:[SERVERNAME]: [[xWebVirtualDirectory]Services] Creating new Web Virtual Directory "Services". Destination element already exists, please use "force" parameter to override. + CategoryInfo : InvalidArgument: (:) [], CimException + FullyQualifiedErrorId : Destination element already exists, please use "force" parameter to override.,Microsoft.IIs.PowerShell.Provider.NewVirtualDirectoryCommand

PraveenKalavai avatar Feb 08 '18 19:02 PraveenKalavai

Thanks for reporting this! Labeled this issue as help wanted so that someone in the community can run with it.

johlju avatar Apr 27 '18 14:04 johlju

Hi all,

I made some tests If you leave WebApplication blank, it works as expected

       xWebVirtualDirectory Services
        {
        Name = "Services"
        Website = "Default Web site"
        WebApplication = ""
        PhysicalPath = "C:\web\"
        Ensure = "Present"
        }

It creates the virtual directory if not present, update it if needed or do nothing if the VD exists.

If you add a WebApplication, if the VD is not present it creates it under Webapplication name (ie /myApp/MyVD), but if this VD exists it throws an error.

The problem seems to be in the way the resource test the existence of the virtual directory

it uses

$virtualDirectory = Get-WebVirtualDirectory -Site $Website `
                                                -Name $Name `
                                                -Application $WebApplication

Where it should use something like

$virtualDirectory = Get-WebVirtualDirectory -Site $Website `
                                                -Name /$WebApplication/$Name `
                                                -Application 

May I try to send a solution?

omiossec avatar Oct 10 '19 14:10 omiossec

bump... still hitting this bug. Any progess? Or easy work around? My VD needs to exist under the web app

blackspy21 avatar Feb 24 '21 13:02 blackspy21

Theory: Use parameter WebApplication only if an application by that name exists in your site.

Not properly tested

Recreated in integration tests:

# Only relevant properties included
WebVirtualDirectory WebVirtualDirectory_WithProblem
{
	WebApplication = 'DummyApp'
	Name = 'dummy'
}
<!-- C:\Windows\System32\inetsrv\config\applicationHost.config -->
<site name="WebsiteForVirtualDirectory" id="2" serverAutoStart="true">
	<application path="/" applicationPool="DefaultAppPool">
		<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot" />
		<virtualDirectory path="/DummyApp/dummy" physicalPath="C:\inetpub\virtualdirectory" />
	</application>
	<application path="/WebApplication" applicationPool="DefaultAppPool">
		<virtualDirectory path="/" physicalPath="C:\inetpub\webapp" />
	</application>
# Only relevant properties included
# This results in identical applicationHost.config, but does NOT have the problem
WebVirtualDirectory WebVirtualDirectory_WorksFine_1
{
	WebApplication = ''
	Name = 'DummyApp/dummy'
}

# This puts the VirtualDirectory under the application "/WebApplication" in applicationHost.config
# This does NOT have the problem
WebVirtualDirectory WebVirtualDirectory_WorksFine_2
{
	WebApplication = 'WebApplication'
	Name = 'dummy'
}

tommysor avatar Nov 09 '22 23:11 tommysor