Deploying websites

Publishing Web Applications

By default website are entirely file based. Source code usually deployed to server which then compiles that code when a page is requested. In this scenario deploy website by copying files to correct directory.

When deploying new version of site, simply overwrite old files with new ones.

Configuration settings defined within web.config and application code contained entirely within website folder structure.

Simplicity => flexibility. To deploy to array of servers use file sync tool to copy files between serves.

If website has database, requires special web server configuration, needs different config settings between staging and release environments, etc. then publishing involves:

  • Configuring IIS
  • Copying files to IIS
  • Setting up database
  • Configuring website to use database
  • Setting config values appropriate to site, e.g. logging levels, error messages, etc.

Visual Studio Publish Web dialogue allows these settings to be set once and then pushed to one (or more) web servers.

Web.config Transformations

Application settings differ between development, staging and live environments.

Web.config transformations allow separate web.config to be created for each environment.

Only need to specify settings to be added, changed or removed from base Web.config file.

By default transformations added for debug and release configurations.

View transformations by expanding Web.Config node and then opening web.config.debug or web.config.relase

If defined new configurations, e.g. staging, then aff associated transformation by right-clicking Web.config and selecting Add Config Transformations.

Adding setting

Simply add the setting to the web.config transformation file.

Replace setting

Add element to web.config transformation file with attribute of xdt:Transform="Replace":

<configuration>

    <system.web>    

        <customErrors defaultRedirect="GenericError.htm" xdt:Transform="Replace">

            <error statusCode="500" redirect="InternalError.htm"/>

        </customErrors>

    </system.web>

</configuration>

Can specify conditions on which replacement to occur via the xdt:Locator attribute:

<configuration>

    <connectionStrings> 

        <add name="MyDB" connectionstring="conn string"  xdt:Transform="Replace" xdt:Locator="Condition(@name='oldname')" />

        </customErrors>

    </connectionStrings>

</configuration>

Without the locator attribute all connection strings would be replaced.

Removing Setting

Set the xdt:Transform attribute to RemoveAttributes() method, passing it the atrribute to remove, e.g.:

<configuration>

    <system.web>    

        <compilation xdt:Transform="RemoveAttributes(debug)" />

    </system.web>

</configuration>

Configuring Deployment

Configure databases to deploy by right clicking project, going to Package/Publish SQL Settings.

Can use Import From Web.config button to configure any database already in web.config

If database does not exist on server deploying to then select Pull Data And./r Schema From An Existing Database check box. Use the Databse Scripting Options list to choose between deploying schema, data, or both. Can also add SQL scripts to perform additional, custom configuration.

Package/Publish Web tab offers additional deployment options, e.g. which files to include, compression and encryption options, whether IIS settings not specified in web.config should be packaged, etc.

Publishing Website

Right click and choose Publish.

Can save publish settings by providing it with a profile name. Settings include:

  • Publish Method - comms protocol to use, e.g. HTTPS, FTP, FPSE (encrypted FTP)
  • Service URL - URL of remote server's web service. Provided by their administrator
  • Site/Application - name of IIS website (can include virtual directory)
  • Mark as IIS Application - Select if website is root of IIS website, or virtual directory should act as separate application from its parent
  • Leave Extra Files On Destination - Determines if existing files removed from web server directory prior to pubication
  • Credentials - required to connect to server

Deployment Packages

If not deploying directly, can package website into zip file for system administrators to install.

Destination server must have Web Deploy installed on it.

Zip file contains <application>.deploy.cmd which is sued to install deployment.

Web Deployment Projects

Post Visual Studio 2010 release by Microsoft.

Extends Visual Studio by adding UI to manage build configurations, merging and pre / post build tasks.

Allow site to be pre-compiled.

Can merge all files into single assembly, or assemblies for each page / control.

Provides strong naming of assemblies

Web Setup Projects

Publishing websites requires specially configured web servers that permit publication to take place. Further, does not support distribution infrastructures requiring MSI packages.

Web Setup Projects provide highest level of deployment flexibility.

Creating Web Setup Project

Similar to standard setup projects

Select File | Add | New Project | Add New Project

From available templates expand Other Project Types | Setup And Deployment | Visual Studio Installer | Web Setup Project

Project added to solution.

From File System Editor create project output group by right clicking Web Application Folder | Add | Project Output. From this dialogue select project to deploy, content files and configuration.

Can add further folders, files and assemblies that are not part of project output.

Building Web Setup Project

Not automatically built, must manually select project and build.

Creating Launch Conditions

Defines server requirements for app installation, e.g. check specific version of Windows present.

To access go to View | Editors | Launch Conditions.

Right click Launch Conditions folder and add a new conditions.

Two main branches to Launch Conditions editor:

  • Search Target Machine - criteria to search for prior to installation, e.g. version of IIS, file and registry conditions. Typically pair search condition (determines if change necessary) with Launch condition (that performs the change)
  • Launch Conditions - define launch conditions that must be met prior to installation. Can be based on search conditions or other criteria (e.g. OS version). Can generate user message if requirement is missing.

Typically add item to each of these nodes to require component as part of installation, e.g. to test specific DLL is present create Search Condition under Search Target Machine and store result of search in a property, then create Launch Condition that uses the search conditions property, if property not set then specify error message to display.

Add Simple Search Condition

Right click Search Target Machine and choose from:

  • Add File Search - set FileName and Folder properties as appropriate. Provide Property for tracking result.
  • Add Registry Search - set RegKey and Value as appropriate. Provide property for tracking result.
  • Add Windows Installer Search - set ComponentId to GUID of required component. Provide property for tracking result.

Add Simple Launch Condition

Right click Launch Conditions and select Add Launch Condition.

Access Properties window to configure launch condition.

Can set Condition property to match the Property value of a search, or specify different condition entirely. Provide URL in InstallUrl property to resolve launch condition. Set Message property to display to user when condition is not met.

The Condition property can be used to check operating system versions, variables, etc. To evaluate environment variables preface with %, e.g.

%HOMEDRIVE = "C:"

Condition can also check installer variables, e.g.

IISVERSION ="#6"

Can combine checks, e.g.

WindowsBuild=2600 AND ServicePackLevel=1

Pre-grouped Launch Conditions

Can create common pre-grouped search and launch conditions.

Right click root node in Launch Conditions editor and choose from:

  • File Launch Condition
  • Registry Launch Condition
  • Windows Installer Launch Condition
  • .NET Framework Launch Condition
  • IIS Launch Condition

Writing To Registry

To access go to View | Editors | Registry.

To add nested key need to add each nested key above it to the editor.

Right click key to add setting, select setting type (String, DWORD, etc.) and then provide a name for the value.

Finally set the value property.

By default key not removed during uninstall, must set the DeleteAtUninstall property to true for this to occur.

Adding Custom Setup Pages

To simplify installation configuration can add custom setup wizard pages and prompt user for install information.

Information collected here can then be passed as parameters to custom actions.

To access go to View | Editors | User Interface

Editor shows different setup phases for both standard and administrative users.

To add custom page right click setup phase to which you want to add and select Add Dialog - n.b. normally added to Start phase under Install mode.

Can customise available dialogue boxes by hiding some controls and displaying different labels.

Adding Custom Actions

Can run in any of four setup phases:

  • insall - performs bulk of work, e.g. adding files, creating config setings
  • commit - finalises changes. After this phase setup cannot be rolled back, instead must be uninstalled.
  • rollback - occurs if setup fails or is cancelled. Used to remove any new files and settings
  • unistall - removes files and settings when application is uninstalled, often leave some entries in place so can be used again if application re-installed

To access go to View | Editors | Custom Actions.

Right click phase to add custom action to then select Add Custom Action.

Select custom.exe or script file to execute at that phase of deployment.

Deploying Web Applications using Web Setup Project

To dpeloy web application to server use files (usually two) generated by build process:

  • Setup.exe - installs files and settings added to Web Setup project. Guides user through installation process and prompts for required information.
  • <WebSetupProjectName>.msi - contains files you added to Web Setup project.

Deploying Web Applications using Copy Web Tool

Web Setup projects useful if providing website to many users.

If you are responsible for updating site it may be impractical to log on to server, copy over installation and run the msi - especially if frequent updates required.

Copy Web Tool can copy individual files or an entire site.

Select source and remote site and move files between them.

Can use to synchronise files - i.e. copying only changed files and detecting version conflicts, n.b. It cannot perform merges.

Launched from Visual Studio - right click site in solution explorer and choose Copy Web Site.

The Remote Site can be:

  • File System - network drive to shared folder on remote server is fastest transfer mechanism. Transfers files in the clear.
  • Local IIS - can create new website on local server
  • FTP Site - requires FTP server on remote server. Transfers credentials and files in the clear.
  • Remote Site - remote site must be configured to allow his form of update. Can use to create new website on remote server. Transfers files in the clear.

Tool will notify of conflicts with remote files, does not provide merging capabilities.

Pre-compiling ASP.NET Websites

ASP.NET Websites (not web applications which are always pre-compiled) pages are compiled the first time they are accessed - performance hit for first visitior. Use pre-compilation to avoid:

Right click web site and select Publishing

Specify publishing location

In Publish Web Site dialogue select appropriate options:

  • Allow this pre-compiled site to be updated - when selected the pages are not compiled into assembly. Markup left in clear allowing changes to be made on server
  • Use fixed naming and single page assemblies - when enabled generates assemblies for each page with intelligible name (rather than random), allows individual page assemblies to be updated later
  • Emit debug information - required if debugging support wanted after publication
  • Enable string naming - generated assemblies are stringly named

Installing ASP.NET 4 on IIS

Optional Windows Update package available to install .NET 4 onto computers.

After framework installed need to configure IIS to support ASP.NET 4 via the aspnet_regiis.exe - located in root of framework installation.

Download