Scott Hanselman

Programmatically Mapping an IIS Vdir/AppPool to .NET Framework 2.0

September 25, '06 Comments [1] Posted in ASP.NET
Sponsored By

We needed to create an IIS Application and Virtual Directory programmatically and while we were doing this, ensure that the VDIR would run only under ASP.NET 2.0. We could certainly shell out to ASPNET_REGIIS.exe to do the work, but this would recycle the whole of IIS (basically every AppPool).

Scott Forsyth at ORCSWeb, my very awesome hosting provider, has an article on a simpler way to make this happen. (It's an older article and older code, but it does work on 2.0 with some simple mods)

It's pretty clever actually...he just spins through the scriptmaps and replaces the current ASP.NET version with the one he wants. The end result is that only that AppPool needs to reset, it's faster, and you don't need to shell out. Thanks ScottF!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Tuesday, September 26, 2006 7:31:04 AM UTC
Some Powershell script code (taken directly from our own ConfigTool/ConfigWebSetup.ps1):

$root = New-Object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC")
$site = $root.get_Children() |Where-Object { $_.ServerComment -eq $AppSiteName }

$webs = $site.get_Children().Find("ROOT", "IIsWebVirtualDir").get_Children()
$web = $webs |Where-Object { $_.get_Name() -eq $AppName }

# $LocalPath = $web.get_Path().Replace("IIS://localhost/", "")
# &C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -sn $LocalPath
$newScriptMaps = $web.ScriptMaps |ForEach-Object { $_ -replace "Framework\\v\d{1}\.\d{1}\.\d{1,5}\\", "Framework\v2.0.50727\" }
$web.ScriptMaps = $newScriptMaps
$web.CommitChanges()
Peter W
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.