Web Project Deployment

Web Project Deployment

An ASP.NET web application can be deployed with either the "one-click publish" or the "deployment package" methods.

  1. One-click publish - is a feature in Visual Studio that lets you deploy by creating a profile and then clicking a button. Visual Studio connects to a destination server and performs the deployment tasks.
  2. deployment package is a .zip file that contains all the information needed for deployment. The package is created and then install it on the destination server
  3. .

One-click publish is typically the best choice for smaller organizations. Before deployment a rollback plan should be created which includes backing up all the code and resources used by the site. While web site projects store the source code on the server, typically a web application project does not. A web application typically compiles the source code into assemblies which are then deployed to the server.

,Deployment


Typical Enterprise Deployment

Deploying a Web Site or Web Application typically involves more than just copying files to the server. Additional setup could include:

  1. Modification of the Web.config file to adjust for the different environment (connection strings, custom error messages, etc.).
  2. Setting IIS configurations on the server (application pool, the authentication method, error handling, etc.).
  3. Installing assemblies in the Global Assembly Cache (GAC) on the server.
  4. Modifications to the server's registry.
  5. Installing security certificates.

Web.config Transformations and Web Deploy Parameters

When a web application is deployed to a different computing environment configurations such as database connection string, authorizations, and error handling usually need to be changed. Two ways to automate this process are Web.config Transformations and Web Deploy Parameters. A Web.config transformation file contains XML which specifies how to change the base Web.config file. Web deploy parameters are useful when you do not know now the configuration values until deployment. Such as when the application is handed over to an IT administrator for deployment.

Web.config transformations, Web.config (XDT) was introduced in Visual Studio 2010 for Web Application Projects (WAP) only. When you create a web application project, three files are created:

  1. Web.config
  2. Web.Debug.config
  3. Web.Release.config

The Debug and Release files contain XML markup called transformation statements (xdt) which are applied to the Web.config when the build type is set to Debug or Release. AppHarbor provides an online Web.config Transformation Tester which allows you see how your Web.config file will be transformed without having to build the project. The default Web.config are listed below.

Web.config
  1. <?xml version="1.0"?>
  2.  
  3. <!--
  4.   For more information on how to configure your ASP.NET application, please visit
  5.   http://go.microsoft.com/fwlink/?LinkId=169433
  6.   -->
  7.  
  8. <configuration>
  9.   <connectionStrings>
  10.     <add name="ApplicationServices"
  11.          connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
  12.          providerName="System.Data.SqlClient" />
  13.   </connectionStrings>
  14.  
  15.   <system.web>
  16.     <compilation debug="true" targetFramework="4.0" />
  17.  
  18.     <authentication mode="Forms">
  19.       <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
  20.     </authentication>
  21.  
  22.     <membership>
  23.       <providers>
  24.         <clear/>
  25.         <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
  26.              enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
  27.              maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
  28.              applicationName="/" />
  29.       </providers>
  30.     </membership>
  31.  
  32.     <profile>
  33.       <providers>
  34.         <clear/>
  35.         <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  36.       </providers>
  37.     </profile>
  38.  
  39.     <roleManager enabled="false">
  40.       <providers>
  41.         <clear/>
  42.         <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
  43.         <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  44.       </providers>
  45.     </roleManager>
  46.  
  47.   </system.web>
  48.  
  49.   <system.webServer>
  50.      <modules runAllManagedModulesForAllRequests="true"/>
  51.   </system.webServer>
  52. </configuration>
Web.Debug.config
  1. <?xml version="1.0"?>
  2.  
  3. <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
  4.  
  5. <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  6.   <!--
  7.     In the example below, the "SetAttributes" transform will change the value of
  8.     "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
  9.     finds an atrribute "name" that has a value of "MyDB".
  10.     
  11.     <connectionStrings>
  12.       <add name="MyDB"
  13.         connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
  14.         xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  15.     </connectionStrings>
  16.   -->
  17.   <system.web>
  18.     <!--
  19.       In the example below, the "Replace" transform will replace the entire
  20.       <customErrors> section of your web.config file.
  21.       Note that because there is only one customErrors section under the
  22.       <system.web> node, there is no need to use the "xdt:Locator" attribute.
  23.       
  24.       <customErrors defaultRedirect="GenericError.htm"
  25.         mode="RemoteOnly" xdt:Transform="Replace">
  26.         <error statusCode="500" redirect="InternalError.htm"/>
  27.       </customErrors>
  28.     -->
  29.   </system.web>
  30. </configuration>
Web.Release.config
  1. <?xml version="1.0"?>
  2.  
  3. <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
  4.  
  5. <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  6.   <!--
  7.     In the example below, the "SetAttributes" transform will change the value of
  8.     "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
  9.     finds an atrribute "name" that has a value of "MyDB".
  10.     
  11.     <connectionStrings>
  12.       <add name="MyDB"
  13.         connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
  14.         xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  15.     </connectionStrings>
  16.   -->
  17.   <system.web>
  18.     <compilation xdt:Transform="RemoveAttributes(debug)" />
  19.     <!--
  20.       In the example below, the "Replace" transform will replace the entire
  21.       <customErrors> section of your web.config file.
  22.       Note that because there is only one customErrors section under the
  23.       <system.web> node, there is no need to use the "xdt:Locator" attribute.
  24.       
  25.       <customErrors defaultRedirect="GenericError.htm"
  26.         mode="RemoteOnly" xdt:Transform="Replace">
  27.         <error statusCode="500" redirect="InternalError.htm"/>
  28.       </customErrors>
  29.     -->
  30.   </system.web>
  31. </configuration>
Error | ASP.NET Developer

Error

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /srv/disk9/1218369/www/kcshadow.net/aspnet/includes/common.inc:2748) in drupal_send_headers() (line 1232 of /srv/disk9/1218369/www/kcshadow.net/aspnet/includes/bootstrap.inc).
  • PDOException: SQLSTATE[42000]: Syntax error or access violation: 1142 INSERT command denied to user '1218369_b2cf'@'185.176.40.58' for table 'watchdog': INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => cron [:db_insert_placeholder_2] => Attempting to re-run cron while it is already running. [:db_insert_placeholder_3] => a:0:{} [:db_insert_placeholder_4] => 4 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://www.kcshadow.net/aspnet/?q=deployment [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => 54.162.171.242 [:db_insert_placeholder_9] => 1534728007 ) in dblog_watchdog() (line 160 of /srv/disk9/1218369/www/kcshadow.net/aspnet/modules/dblog/dblog.module).
The website encountered an unexpected error. Please try again later.