Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 107cfe8

Browse files
committed
Add virtual directory example
1 parent 0d91571 commit 107cfe8

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

examples/04-CreateVDir/IIS.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
mkdir "C:\Sites\MyApp" -ErrorAction SilentlyContinue
11+
12+
New-IISSite -Name "Website1" -BindingInformation "*:8022:" -PhysicalPath "C:\Sites\Website1"
13+
14+
# -----------------------------------------------------------------------------
15+
# Example
16+
# -----------------------------------------------------------------------------
17+
Import-Module IISAdministration
18+
19+
$manager = Get-IISServerManager
20+
$app = $manager.Sites["Website1"].Applications.Add("/MyApp", "C:\Sites\MyApp")
21+
$app.ApplicationPoolName = ".NET v2.0"
22+
$manager.CommitChanges()
23+
24+
# -----------------------------------------------------------------------------
25+
# Assert
26+
# -----------------------------------------------------------------------------
27+
28+
# -----------------------------------------------------------------------------
29+
# Clean up
30+
# -----------------------------------------------------------------------------
31+
32+
. ..\_Teardown.IIS.ps1
33+
34+
Remove-IISSite -Name "Website1" -Confirm:$false

examples/04-CreateVDir/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Creating applications in virtual directories
2+
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.

examples/04-CreateVDir/Web.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
14+
# -----------------------------------------------------------------------------
15+
# Example
16+
# -----------------------------------------------------------------------------
17+
18+
Import-Module WebAdministration
19+
20+
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"
22+
23+
# -----------------------------------------------------------------------------
24+
# Assert
25+
# -----------------------------------------------------------------------------
26+
27+
if ((Test-Path IIS:\Sites\Website1\MyApp) -eq $false) { Write-Error "App not found" }
28+
if ((Get-ItemProperty -Path "IIS:\Sites\Website1\MyApp" -name "applicationPool") -ne ".NET v2.0") { Write-Error "Wrong app pool" }
29+
30+
# -----------------------------------------------------------------------------
31+
# Clean up
32+
# -----------------------------------------------------------------------------
33+
34+
. ..\_Teardown.Web.ps1
35+
36+
Remove-Item -Path "IIS:\Sites\Website1" -Recurse -Force

0 commit comments

Comments
 (0)