您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

85 行
2.9KB

  1. param(
  2. [string]$OutputPath = "$(Join-Path $PSScriptRoot 'applicationhost.config')",
  3. [string]$BaseConfigPath = "$env:ProgramFiles\IIS Express\AppServer\applicationhost.config",
  4. [string]$SiteName = "AspClassicPublicSite",
  5. [string]$PhysicalPath = "H:\AI - ASP - Classic\Public",
  6. [string]$BindingInformation = "*:8080:localhost"
  7. )
  8. if (-not (Test-Path -LiteralPath $BaseConfigPath)) {
  9. $BaseConfigPath = "$env:ProgramFiles(x86)\IIS Express\AppServer\applicationhost.config"
  10. }
  11. if (-not (Test-Path -LiteralPath $BaseConfigPath)) {
  12. Write-Error "IIS Express base applicationhost.config not found."
  13. exit 1
  14. }
  15. [xml]$xml = Get-Content -LiteralPath $BaseConfigPath
  16. $sitesNode = $xml.configuration.'system.applicationHost'.sites
  17. if (-not $sitesNode) {
  18. Write-Error "Base config does not contain system.applicationHost/sites."
  19. exit 1
  20. }
  21. $existingSite = $sitesNode.site | Where-Object { $_.name -eq $SiteName }
  22. if ($existingSite) {
  23. [void]$sitesNode.RemoveChild($existingSite)
  24. }
  25. $siteIds = @($sitesNode.site | ForEach-Object { [int]$_.id })
  26. $nextId = if ($siteIds.Count -gt 0) { ($siteIds | Measure-Object -Maximum).Maximum + 1 } else { 1 }
  27. $site = $xml.CreateElement('site')
  28. $site.SetAttribute('name', $SiteName)
  29. $site.SetAttribute('id', [string]$nextId)
  30. $site.SetAttribute('serverAutoStart', 'true')
  31. $application = $xml.CreateElement('application')
  32. $application.SetAttribute('path', '/')
  33. $application.SetAttribute('applicationPool', 'Clr4IntegratedAppPool')
  34. $virtualDirectory = $xml.CreateElement('virtualDirectory')
  35. $virtualDirectory.SetAttribute('path', '/')
  36. $virtualDirectory.SetAttribute('physicalPath', $PhysicalPath)
  37. [void]$application.AppendChild($virtualDirectory)
  38. $bindings = $xml.CreateElement('bindings')
  39. $binding = $xml.CreateElement('binding')
  40. $binding.SetAttribute('protocol', 'http')
  41. $binding.SetAttribute('bindingInformation', $BindingInformation)
  42. [void]$bindings.AppendChild($binding)
  43. [void]$site.AppendChild($application)
  44. [void]$site.AppendChild($bindings)
  45. [void]$sitesNode.AppendChild($site)
  46. $oldLocation = @($xml.configuration.location | Where-Object { $_.path -eq $SiteName })
  47. foreach ($node in $oldLocation) {
  48. [void]$xml.configuration.RemoveChild($node)
  49. }
  50. $location = $xml.CreateElement('location')
  51. $location.SetAttribute('path', $SiteName)
  52. $systemWebServer = $xml.CreateElement('system.webServer')
  53. $directoryBrowse = $xml.CreateElement('directoryBrowse')
  54. $directoryBrowse.SetAttribute('enabled', 'false')
  55. $asp = $xml.CreateElement('asp')
  56. $asp.SetAttribute('scriptErrorSentToBrowser', 'true')
  57. $asp.SetAttribute('enableParentPaths', 'true')
  58. $limits = $xml.CreateElement('limits')
  59. $limits.SetAttribute('scriptTimeout', '00:10:00')
  60. [void]$asp.AppendChild($limits)
  61. [void]$systemWebServer.AppendChild($directoryBrowse)
  62. [void]$systemWebServer.AppendChild($asp)
  63. [void]$location.AppendChild($systemWebServer)
  64. [void]$xml.configuration.AppendChild($location)
  65. $xml.Save($OutputPath)
  66. Write-Host "Generated IIS Express config at $OutputPath"

Powered by TurnKey Linux.