Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 0a7ded9

Browse files
Switch examples to show sites, vdirs, then creating and assigning app pools
1 parent 1c7e011 commit 0a7ded9

File tree

10 files changed

+105
-30
lines changed

10 files changed

+105
-30
lines changed

‎examples/03-CreateAppPool/README.md‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎examples/04-CreateVDir/IIS.ps1‎ renamed to ‎examples/03-CreateVDir/IIS.ps1‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Import-Module IISAdministration
1818

1919
$manager = Get-IISServerManager
2020
$app = $manager.Sites["Website1"].Applications.Add("/MyApp", "C:\Sites\MyApp")
21-
$app.ApplicationPoolName = ".NET v2.0"
2221
$manager.CommitChanges()
2322

2423
# -----------------------------------------------------------------------------
File renamed without changes.

‎examples/04-CreateVDir/Web.ps1‎ renamed to ‎examples/03-CreateVDir/Web.ps1‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ New-Website -Name "Website1" -Port 80 -IPAddress "*" -HostHeader "" -PhysicalPat
1818
Import-Module WebAdministration
1919

2020
New-Item -Type Application -Path "IIS:\Sites\Website1\MyApp" -physicalPath "C:\Sites\MyApp"
21-
Set-ItemProperty -Path "IIS:\Sites\Website1\MyApp" -name "applicationPool" -value ".NET v2.0"
2221

2322
# -----------------------------------------------------------------------------
2423
# Assert

‎examples/03-CreateAppPool/IIS.ps1‎ renamed to ‎examples/04-CreateAppPool/IIS.ps1‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@ cd $here
66

77
. ..\_Setup.IIS.ps1
88

9-
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10-
11-
New-IISSite -Name "Website1" -BindingInformation "*:8022:" -PhysicalPath "C:\Sites\Website1"
12-
139
# -----------------------------------------------------------------------------
1410
# Example
1511
# -----------------------------------------------------------------------------
1612
Import-Module IISAdministration
1713

18-
$pool = Get-IISAppPool -Name "My Pool 3" -WarningAction SilentlyContinue
14+
$pool = Get-IISAppPool -Name "My Pool" -WarningAction SilentlyContinue
1915
if ($pool -eq $null) {
2016
$manager = Get-IISServerManager
21-
$pool = $manager.ApplicationPools.Add("My Pool 3")
17+
$pool = $manager.ApplicationPools.Add("My Pool")
2218

2319
# Older applications may require "Classic" mode, but most modern ASP.NET
2420
# apps use the integrated pipeline
@@ -56,23 +52,18 @@ if ($pool -eq $null) {
5652
$manager.CommitChanges()
5753
}
5854

59-
$website = Get-IISSite -Name "Website1"
60-
$website.Applications["/"].ApplicationPoolName = "My Pool 3"
61-
6255
# -----------------------------------------------------------------------------
6356
# Assert
6457
# -----------------------------------------------------------------------------
6558

66-
if ((Get-IISAppPool -Name "My Pool 3") -eq $null) { Write-Error "My Pool not found" }
59+
if ((Get-IISAppPool -Name "My Pool") -eq $null) { Write-Error "My Pool not found" }
6760

6861
# -----------------------------------------------------------------------------
6962
# Clean up
7063
# -----------------------------------------------------------------------------
7164

7265
. ..\_Teardown.IIS.ps1
7366

74-
Remove-IISSite -Name "Website1" -Confirm:$false
75-
7667
$manager = Get-IISServerManager
77-
$manager.ApplicationPools["My Pool 3"].Delete()
68+
$manager.ApplicationPools["My Pool"].Delete()
7869
$manager.CommitChanges()

‎examples/04-CreateAppPool/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Creating application pools
2+
3+
You need to assign each application (website or application in a virtual directory) to an *application pool*. The application pool defines the executable process in which requests to the application are handled.
4+
5+
IIS comes with a handful of application pools already defined for common options, but I always recommend creating your own application pool for each website or application that you deploy. This provides process-level isolation between applications and lets you set different permissions around what each application can do. The examples below show many of the common application pool settings. For the IIS Administration module, there are no built-in CmdLets to create application pools, so you have to do it with the `ServerManager` object directly.

‎examples/03-CreateAppPool/Web.ps1‎ renamed to ‎examples/04-CreateAppPool/Web.ps1‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ cd $here
66

77
. ..\_Setup.Web.ps1
88

9-
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10-
11-
New-Website -Name "Website1" -Port 80 -IPAddress "*" -HostHeader "" -PhysicalPath "C:\Sites\Website1"
12-
139
# -----------------------------------------------------------------------------
1410
# Example
1511
# -----------------------------------------------------------------------------
@@ -88,15 +84,11 @@ if ((Test-Path "IIS:\AppPools\My Pool 3") -eq $False) {
8884
}
8985
}
9086

91-
# Assign application pool to website
92-
Set-ItemProperty -Path "IIS:\Sites\Website1" -name "applicationPool" -value "My Pool 3"
93-
9487
# -----------------------------------------------------------------------------
9588
# Assert
9689
# -----------------------------------------------------------------------------
9790

9891
if ((Get-WebAppPoolState -Name "My Pool 3") -eq $null) { Write-Error "Website1 not found" }
99-
if ((Get-WebSite -Name "Website1") -eq $null) { Write-Error "Website1 not found" }
10092
if ((Get-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "managedPipelineMode") -ne "Integrated") { Write-Error "Wrong pipeline mode" }
10193

10294
# -----------------------------------------------------------------------------
@@ -105,5 +97,4 @@ if ((Get-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "managedPipelineMode
10597

10698
. ..\_Teardown.Web.ps1
10799

108-
Remove-Item -Path "IIS:\Sites\Website1" -Recurse -Force
109-
Remove-Item -Path "IIS:\AppPools\My Pool 3" -Recurse -Force
100+
Remove-Item -Path "IIS:\AppPools\My Pool 3" -Recurse -Force
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -----------------------------------------------------------------------------
2+
# Setup
3+
# -----------------------------------------------------------------------------
4+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
cd $here
6+
7+
. ..\_Setup.IIS.ps1
8+
9+
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10+
11+
New-IISSite -Name "Website1" -BindingInformation "*:8022:" -PhysicalPath "C:\Sites\Website1"
12+
13+
$manager = Get-IISServerManager
14+
$pool = $manager.ApplicationPools.Add("My Pool")
15+
$app = $manager.Sites["Website1"].Applications.Add("/MyApp", "C:\Sites\MyApp")
16+
$manager.CommitChanges()
17+
18+
# -----------------------------------------------------------------------------
19+
# Example
20+
# -----------------------------------------------------------------------------
21+
Import-Module IISAdministration
22+
23+
$manager = Get-IISServerManager
24+
25+
# Assign to a website
26+
$website = $manager.Sites["Website1"]
27+
$website.Applications["/"].ApplicationPoolName = "My Pool"
28+
29+
# Assign to an application in a virtual directory
30+
$website = $manager.Sites["Website1"]
31+
$website.Applications["/MyApp"].ApplicationPoolName = "My Pool"
32+
33+
$manager.CommitChanges()
34+
35+
# -----------------------------------------------------------------------------
36+
# Assert
37+
# -----------------------------------------------------------------------------
38+
39+
if ((Get-IISAppPool -Name "My Pool") -eq $null) { Write-Error "My Pool not found" }
40+
41+
# -----------------------------------------------------------------------------
42+
# Clean up
43+
# -----------------------------------------------------------------------------
44+
45+
. ..\_Teardown.IIS.ps1
46+
47+
Remove-IISSite -Name "Website1" -Confirm:$false
48+
49+
$manager = Get-IISServerManager
50+
$manager.ApplicationPools["My Pool 3"].Delete()
51+
$manager.CommitChanges()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
### Creating applications in virtual directories
1+
### Assigning application pools
22

3-
Most of the time, when people think of deploying a .NET app to a "virtual directory", they mean creating an *application* underneath a web site. The example below creates an application that would be viewable at `http://site/MyApp`. We also assign an application pool.
3+
Once you've defined your application pool, you must assign applications to it. The examples below show you how to assign websites or applications in a virtual directory to your new application pool.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -----------------------------------------------------------------------------
2+
# Setup
3+
# -----------------------------------------------------------------------------
4+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
cd $here
6+
7+
. ..\_Setup.Web.ps1
8+
9+
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10+
mkdir "C:\Sites\MyApp" -ErrorAction SilentlyContinue
11+
12+
New-Website -Name "Website1" -Port 80 -IPAddress "*" -HostHeader "" -PhysicalPath "C:\Sites\Website1"
13+
New-Item -Type Application -Path "IIS:\Sites\Website1\MyApp" -physicalPath "C:\Sites\MyApp"
14+
New-Item -Path "IIS:\AppPools" -Name "My Pool" -Type AppPool
15+
16+
# -----------------------------------------------------------------------------
17+
# Example
18+
# -----------------------------------------------------------------------------
19+
20+
Import-Module WebAdministration
21+
22+
# Assign the application pool to a website
23+
Set-ItemProperty -Path "IIS:\Sites\Website1" -name "applicationPool" -value "My Pool"
24+
25+
# Assign the application pool to an application in a virtual directory
26+
Set-ItemProperty -Path "IIS:\Sites\Website1\MyApp" -name "applicationPool" -value "My Pool"
27+
28+
# -----------------------------------------------------------------------------
29+
# Assert
30+
# -----------------------------------------------------------------------------
31+
32+
if ((Test-Path IIS:\Sites\Website1\MyApp) -eq $false) { Write-Error "App not found" }
33+
if ((Get-ItemProperty -Path "IIS:\Sites\Website1\MyApp" -name "applicationPool") -ne "My Pool") { Write-Error "Wrong app pool" }
34+
35+
# -----------------------------------------------------------------------------
36+
# Clean up
37+
# -----------------------------------------------------------------------------
38+
39+
. ..\_Teardown.Web.ps1
40+
41+
Remove-Item -Path "IIS:\Sites\Website1" -Recurse -Force
42+
Remove-Item -Path "IIS:\AppPools\My Pool" -Recurse -Force

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /