Near Infinity

ASP .NET MVC Windows Server Setup

By Sean Howell

Jun 04, 2012

This is a collection of script I have used to setup a Windows 2008 R2 server for a ASP .NET MVC web application. The scripts setup IIS, SQL Server and Windows. The following code sets up the core features of Windows including IIS, the .NET framework and allows Remote Desktop connections.

 1     import servermanager # Provides the Add-WindowsFeature cmdlet
 2 
 3     function wait-process($processName, $arguments)
 4     {
 5             start-process $processName -argumentlist $arguments -wait 
 6     }
 7 
 8     write-host "Adding core windows features"
 9     Add-WindowsFeature WAS,NET-Framework -includeAllSubFeature 
10 
11     write-host "Installing .NET Framework 4"
12     wait-process ".\\dotNetFx40_Full_setup.exe" @("/install", "/q", "/norestart")
13 
14     write-host "Enabling Remote Desktop"
15     $terminal = gwmi Win32_TerminalServiceSetting -Namespace ROOT\\CIMV2\\TerminalServices
16     $settings = (Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\\cimv2\\terminalservices -Filter "TerminalName='RDP-tcp'")
17     $r = $terminal.SetAllowTSConnections(1)
18     $settings.SetUserAuthenticationRequired(1)
19 
20     write-host "Configuring Windows Firewall to allow Remote Desktop connections"
21     netsh advfirewall Firewall set rule group="Remote Desktop" new enable="yes" 

Next on the setup list is adding roles to IIS. The following cmd file will add all of the required roles to run a ASP .NET MVC application. However, this is by no means a the minimal set of Windows features required to run an ASP .NET MVC application.

1     roles.cmd
2 
3     start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;
4     IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;
5     IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;IIS-DigestAuthentication;
6     IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;
7     IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementService;IIS-Metabase;
8     WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI /norestart

Now that the features for the MVC application are installed, it is time to add MsWebDeploy and register .NET with IIS. MS Web Deploy(5/30/2012)

1     write-host "Registering .NET with IIS"
2     &"C:\\WINDOWS\\Microsoft.NET\\Framework64\\v4.0.30319\\aspnet_regiis" -i
3 
4     write-host "Installing MsWebDeploy"
5     wait-process "msiexec" @("/i WebDeploy_2_10_amd64_en-US.msi", "ADDLOCAL=ALL", "/qn", "/norestart")

Next up is the install of SQL Server and the install of SQL Server CE. You can skip installing SQL Server CE if you don't use the Visual Studio's database project for database deployment. However, if you use the database project then SQL Server CE x86/x64 must be on the server the deploy is running from. SQL Ce(5/30/2012)

 1     $admin = "" # Choose your administrator for SQL Server
 2     $path = (get-location).path
 3     write-host "Installing SQL Server"
 4     $configurations = @("/CONFIGURATIONFILE=$path\\Configuration.ini", "/QUIETSIMPLE", "/IACCEPTSQLSERVERLICENSETERMS", "/SQLSYSADMINACCOUNTS=$admin")
 5     $extraConfigurations | %{ $configurations += $_ } # Parameter to the file to add more configurations.
 6     wait-process ".\\SQLEXPR_x64_ENU.exe" $configurations
 7 
 8     write-host "Installing SQL Ce SP 2 x86"
 9     wait-process "msiexec" @("/i SSCERuntime_x86-ENU.msi", "/qn")
10 
11     write-host "Installing SQL Ce SP 2 x64"
12     wait-process "msiexec" @("/i SSCERuntime_x64-ENU.msi", "/qn")

The basic web application will now run on the Windows server.