WebAdministrationDsc
WebAdministrationDsc copied to clipboard
xWebVirtualDirectory Fails to create a virtual directory if it already exists
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
Thanks for reporting this! Labeled this issue as help wanted so that someone in the community can run with it.
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?
bump... still hitting this bug. Any progess? Or easy work around? My VD needs to exist under the web app
Theory: Use parameter
WebApplication
only if anapplication
by that name exists in yoursite
.
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'
}