A New Site - Quick!

For testing purposes I sometimes need a new IIS site, often times running in its own AppPool. And I usually need it fast and without much programming. I hate ports and so I normally put my site name in the hosts file. Locally this works great!

Because I'm an old kind-a guy I still use batch files with some pixie dust from appcmd. I thought somebody might find this script useful, too:

@ECHO OFF
REM ===============================================================================================
REM CREATE A NEW SITE IN ITS OWN APPPOOL.
REM ARGUMENTS: SITENAME
REM
REM STEPS:
REM 1) SETUP AND ARGUMENTS CHECKS
REM 2) CREATE APPPOOL (SAME NAME AS SITE)
REM 3) CREATE DIRECTORY c:\inetpub\<sitename>
REM 4) CREATE DEFAULT.ASPX FILE IN c:\inetpub\<sitename>
REM 5) CREATE SITE WITH PHYSICALPATH c:\inetpub\<sitename>
REM 6) ASSIGN SITE ROOT APP TO APPLICATIONPOOL <sitename>
REM 7) ADD SITENAME TO HOSTS FILE RESOLVING TO 127.0.0.1
REM 8) LAUNCH IE WITH SITE
REM ===============================================================================================



REM GOTO USAGE IF NO COMMAND-LINE ARGUMENTS
if "%1" == "" GOTO USAGE




REM CREATE SOME LOCAL VARIABLES
SETLOCAL
SET NEWDIR="%SYSTEMDRIVE%\inetpub\%1"
SET APPCMD=%WINDIR%\system32\inetsrv\appcmd.exe




@ECHO CREATE THE APPPOOL
%APPCMD% ADD APPPOOL /NAME:"%1"


@ECHO CREATE THE CONTENT DIRECTORY
MD %NEWDIR%


@ECHO CREATE DEFAULT.ASPX FILE IN CONTENT DIRECTORY
ECHO ^<%%=DateTime.Now%%^> > "%NEWDIR%\default.aspx"


@ECHO CREATE NEW SITE
%APPCMD% ADD SITE /NAME:"%1" /BINDINGS:"http://%1:80" /PHYSICALPATH:"%NEWDIR%"


@ECHO ASSIGN TO APPLICATION POOL
%APPCMD% SET APP "%1/" /APPLICATIONPOOL:"%1"


@ECHO ADD SITENAME TO HOSTS FILE
ECHO 127.0.0.1 %1 >> %WINDIR%\system32\drivers\etc\hosts


@ECHO LAUNCH INTERNET EXPLORER WITH THE NEW SITE
START IEXPLORE http://%1/
REM USAGE MESSAGE IF NO COMMAND-LINE ARGUMENT WAS GIVEN

GOTO EXIT
:USAGE
@ECHO USAGE: %0 ^<name of new site^>
@ECHO Example: "%0 MyNewSite"
:EXIT

 

No Comments