Vb.net 使用IIS Express而不是IIS以编程方式添加IIS应用程序池/应用程序
我有一个创建应用程序池和应用程序的Visual Basic应用程序。在64位Windows 8计算机上运行它会导致在IIS Express 8.0而不是IIS 8.0中创建池和应用程序。我已在\documents\IISExpress中打开applicationhost.config,并验证是否正在那里进行更改。如果您能深入了解如何瞄准IIS而不是IIS Express,我将不胜感激。配置应用程序通常在web服务器上运行,但也需要在开发机器上运行。以下是获取IIS版本的代码:Vb.net 使用IIS Express而不是IIS以编程方式添加IIS应用程序池/应用程序,vb.net,iis-express,iis-8,servermanager,Vb.net,Iis Express,Iis 8,Servermanager,我有一个创建应用程序池和应用程序的Visual Basic应用程序。在64位Windows 8计算机上运行它会导致在IIS Express 8.0而不是IIS 8.0中创建池和应用程序。我已在\documents\IISExpress中打开applicationhost.config,并验证是否正在那里进行更改。如果您能深入了解如何瞄准IIS而不是IIS Express,我将不胜感激。配置应用程序通常在web服务器上运行,但也需要在开发机器上运行。以下是获取IIS版本的代码: Dim rootI
Dim rootId As DirectoryEntry = GetDirectoryEntry(String.Format("IIS://{0}/W3SVC/Info", DomainName))
If rootId IsNot Nothing Then
Try
If rootId.Properties.Contains("MajorIIsVersionNumber") = True Then
Dim iisVal As String = rootId.Properties("MajorIIsVersionNumber").Value.ToString
对上面的域名同时使用localhost和machine名称将其连接到IIS Express。下面是我创建应用程序池的函数。设置poolName变量的循环用于调试,以帮助确定它正在使用IIS Express。同样,它可以工作,但会在IIS Express中创建池
Private Function GetOrCreateAppPool(ByRef mgr As ServerManager, ByVal domainPath As String, ByVal appPoolName As String, ByVal addAppPool As Boolean) As ApplicationPool
' First see if app pool exists
Dim appPoolId As ApplicationPool = Nothing
Dim poolId As ApplicationPool
Dim poolName As String
For Each poolId In mgr.ApplicationPools
poolName = poolId.Name
Next
appPoolId = mgr.ApplicationPools(appPoolName)
If appPoolId Is Nothing Then
appPoolId = mgr.ApplicationPools.Add(appPoolName)
If appPoolId IsNot Nothing Then
With appPoolId
.AutoStart = True
.ManagedPipelineMode = ManagedPipelineMode.Integrated
.ManagedRuntimeVersion = "v4.0"
.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService
.ProcessModel.IdleTimeout = TimeSpan.FromMinutes(240)
.Recycling.PeriodicRestart.Time = TimeSpan.FromMinutes(0)
.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("03:00:00"))
End With
mgr.CommitChanges()
End If
End If
Return appPoolId
End Function
感谢您的帮助。默认情况下,Microsoft.Web.Administration是7.9.0.0版,仅对IIS Express有效
Private Function GetOrCreateAppPool(ByRef mgr As ServerManager, ByVal domainPath As String, ByVal appPoolName As String, ByVal addAppPool As Boolean) As ApplicationPool
' First see if app pool exists
Dim appPoolId As ApplicationPool = Nothing
Dim poolId As ApplicationPool
Dim poolName As String
For Each poolId In mgr.ApplicationPools
poolName = poolId.Name
Next
appPoolId = mgr.ApplicationPools(appPoolName)
If appPoolId Is Nothing Then
appPoolId = mgr.ApplicationPools.Add(appPoolName)
If appPoolId IsNot Nothing Then
With appPoolId
.AutoStart = True
.ManagedPipelineMode = ManagedPipelineMode.Integrated
.ManagedRuntimeVersion = "v4.0"
.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService
.ProcessModel.IdleTimeout = TimeSpan.FromMinutes(240)
.Recycling.PeriodicRestart.Time = TimeSpan.FromMinutes(0)
.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("03:00:00"))
End With
mgr.CommitChanges()
End If
End If
Return appPoolId
End Function
添加Microsoft.Web.Administration 7.0.0.0,您将能够管理IIS服务器。使用NuGet很容易找到它。应该避免使用NuGet包,特别是对于IIS 8+用户。