1

次のコードは、VS2005 でプロジェクトをコンパイルしたときに、IIS を構成して ApplicationPool をセットアップし、(InstallerClass を使用して) それに WebApplication を正常に割り当てるのに役立ちます。

VS2010 でコンパイル中に問題が発生しました。インストール セットアップを実行しているときに、サイトのアプリケーション プールを選択するために DropDownList になり (以前はありませんでした)、作成している AppPool がリストにありません。

インストール後に AppPool が作成され、表示されますが、アプリケーションがバインドされていません。

私が欠けているものについて誰か考えがありますか? 助けてくれてありがとう。よろしく、アミン

PS: コード:

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
4

0 に答える 0