following code helps me configuring my IIS to setup an ApplicationPool and assign my WebApplication to it (using InstallerClass) successfuly when I compiled my projects under VS2005.
Now I'm having troubles while compiling under VS2010! When I'm running my installation setup, I become now a DropDownList to choose an application pool for the site (I did not hav this before) and in the list there is not my AppPool that I'm creating.
The AppPool will be created after the installation, I can see it, but my application is not bind to it.
Have anyone an idea about what am I missing? thanks much for helping. Greets, amine
PS: code:
Private Const _appPoolName As String = "MyPool001"
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
SetIISApplicationPool(_appPoolName, Me.Context)
End Sub
Public Shared Sub SetIISApplicationPool(ByVal AppPoolName As String, ByVal context As System.Configuration.Install.InstallContext)
Dim targetSite As String = context.Parameters("targetsite")
Dim targetVDir As String = context.Parameters("targetvdir")
Dim targetDirectory As String = context.Parameters("targetdir")
If targetSite Is DBNull.Value Then
Throw New System.Configuration.Install.InstallException("IIS Site Name Not Specified!")
End If
If targetSite.StartsWith("/LM/") Then
'// Sets the virtual directory to .NET 2.0
targetSite = targetSite.Substring(4)
Dim info As New ProcessStartInfo
info.FileName = IO.Path.Combine(System.Environment.GetEnvironmentVariable("SystemRoot"), "Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe")
info.Arguments = String.Format("-s {0}/ROOT/{1}", targetSite, targetVDir)
info.CreateNoWindow = True
info.UseShellExecute = False
Process.Start(info)
Try
CreateApplicationPool("IIS://localhost/W3SVC/AppPools", AppPoolName)
Catch : End Try
Try
AssignVDirToAppPool("IIS://localhost/" & targetSite & "/Root/" & targetVDir, AppPoolName)
Catch : End Try
End If
End Sub
Private Shared Sub CreateApplicationPool(ByVal strMetabasePath As String, ByVal strAppPoolName As String)
Try
If strMetabasePath.EndsWith("/W3SVC/AppPools") Then
Dim blExists As Boolean = AppPoolExists(strMetabasePath, strAppPoolName)
If blExists = False Then
Dim objNewPool As System.DirectoryServices.DirectoryEntry
Dim objAppPools As New System.DirectoryServices.DirectoryEntry(strMetabasePath)
objNewPool = objAppPools.Children.Add(strAppPoolName, "IIsApplicationPool")
objNewPool.CommitChanges()
End If
Else
Throw New Exception("Application pools can only be created in the */W3SVC/AppPools node.")
End If
Catch exError As Exception
Throw New Exception("Failed in CreateAppPool with the following exception: " & exError.Message)
End Try
End Sub
Private Shared Sub AssignVDirToAppPool(ByVal strMetabasePath As String, ByVal strAppPoolName As String)
Try
Dim objVdir As New System.DirectoryServices.DirectoryEntry(strMetabasePath)
Dim strClassName As String = objVdir.SchemaClassName.ToString()
If strClassName.EndsWith("VirtualDir") Then
Dim objParam As Object() = {0, strAppPoolName, True}
objVdir.Invoke("AppCreate3", objParam)
objVdir.Properties("AppIsolated")(0) = "2"
Else
Throw New Exception("Only virtual directories can be assigned to application pools")
End If
Catch exError As Exception
Throw New Exception("Failed in AssignVDirToAppPool with the following exception: " & exError.Message)
End Try
End Sub
Private Shared Function AppPoolExists(ByVal strMetabasePath As String, ByVal strAppPoolName As String) As Boolean
strMetabasePath += "/" & strAppPoolName
Dim blExists As Boolean = False
If System.DirectoryServices.DirectoryEntry.Exists(strMetabasePath) = True Then
blExists = True
End If
Return blExists
End Function