Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: IIS6 VB.NET
Hi All,
 
I'm trying to install a web setup in that i'm using custom actions for deleting the default virtual directories which is created by the MSI and creating custom virtual directories.
The directories are creating fine, but the when I reset the IIS the custom virtual directories are gone and the deleted default virtual directories are came.
 
Resources used : Windows server 2003, IIS 6
 
Here the code used for deleting virtual directory and creatign virtual directory
 
Create Virtual Directory:
<pre lang="vb">Private Sub CreateVDir(ByVal strMetabasePath As String, ByVal strVdirName As String, ByVal strPhysicalPath As String, ByVal AppName As String)
        Try
            Dim objSite As New DirectoryEntry(strMetabasePath)
 
            If (CheckIfVDirExists(objSite, strVdirName)) Then
                DeleteVirtualDirectory(strVdirName)
            End If
 
            Dim strClassName As String = objSite.SchemaClassName.ToString()
            If strClassName.EndsWith("Server") OrElse strClassName.EndsWith("VirtualDir") Then
                Dim objVdirs As DirectoryEntries = objSite.Children
                Dim objNewVdir As DirectoryEntry = objVdirs.Add(strVdirName, strClassName.Replace("Service", "VirtualDir"))
                objNewVdir.Properties("Path")(0) = strPhysicalPath
                objNewVdir.Properties("AccessScript")(0) = True
                objNewVdir.Properties("AppFriendlyName")(0) = strVdirName
                objNewVdir.Properties("AppIsolated")(0) = "1"
                objNewVdir.Properties("AppPoolId").Value = AppName
                objNewVdir.Properties("AppRoot")(0) = "/LM" + strMetabasePath.Substring(strMetabasePath.IndexOf("/", "IIS://".Length))
                objNewVdir.CommitChanges()
                objNewVdir.Properties("AppFriendlyName")(0) = strVdirName
                objNewVdir.Invoke("AppCreate", True)
                objSite.CommitChanges()
            Else
                Throw New InstallException("Failed. A virtual directory can only be created in a site or virtual directory node.")
            End If
        Catch exError As Exception
            Throw exError
        End Try
    End Sub
 
Delete Virtual Directory:
Private Sub DeleteVirtualDirectory(ByVal VirtualDirName As String)
        Try
            Dim Parent As New DirectoryEntry(StrMetabasePath)
            Dim Parameters As [Object]() = {"IIsWebVirtualDir", VirtualDirName}
            Parent.Invoke("Delete", Parameters)
            Parent.CommitChanges()
        Catch ex As Exception
           Throw New InstallException("Error While deleting the virtual directories." & ex.Message)
        End Try
    End Sub
 

Thanks,
Dhilip
Posted 25-Mar-13 6:00am
Edited 25-Mar-13 6:09am
v2
Comments
iismoove at 2-Apr-13 15:10pm
   
Have you tried stopping IIS before you delete the VDir? I noticed with our IIS, we need to stop it, create/delete the VDir, and then restart IIS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 451
1 Afzaal Ahmad Zeeshan 184
2 /\jmot 176
3 Marcin Kozub 150
4 Sergey Alexandrovich Kryukov 150
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100