Export (0) Print
Expand All

Walkthrough: Deploying a Web Application Project Using One-Click Publish

.NET Framework 4

This walkthrough illustrates how to deploy a Web application project to a Web hosting company by using one-click publish. The project to deploy includes the ASP.NET membership database and illustrates the following tasks:

  • Initial deployment of Web application files and of the database.

  • Subsequent deployment of updates to the Web application without database changes.

NoteNote

Web deployment tools have been improved in Visual Studio 2012. You can install the improved tools in Visual Studio 2010 and Visual Web Developer 2010 Express by installing the Visual Studio Web Publish Update. For information about how to use the new tools, see the documentation for Visual Studio 2012. A good place to start is Web Application Project Deployment Overview for Visual Studio and ASP.NET.

In order to complete this walkthrough, you will need:

  • Visual Studio or Visual Web Developer Express.

    NoteNote

    If you are using Visual Studio, the walkthrough assumes that you selected the Web Development collection of settings when you started Visual Studio the first time. For more information, see How to: Select Web Development Environment Settings.

  • An account with a Web hosting company that supports one-click publish. If you do not already have such an account, you must sign up for one. For information about how to find a hosting company, see WebsiteSpark Partner Catalog.

To set up one-click deployment, you must have the following information from the Web hosting company:

  • The service URL for your hosting account. This is a URL that points to the IIS handler that manages deployment on the hosting company's Web server. The URL is typically in the format https://prefix.hostingcompanyname.com or https://prefix.hostingcompanyname.com:8172/MsDeploy.axd.

  • The name of your Web site and application name, separated by a slash character (/). The hosting company will typically use the name "Site/application" when it provides this information. Alternatively, the hosting company might specify only the site name. In that case you can specify whatever name you choose as the application name.

  • The user name and password of an account that has permissions to update your site on the hosting company's Web server.

  • A connection string that can be used to access your site's database on the hosting company's database server. The login credentials in the connection string must have permissions to update the structure of the database.

  • Information about whether you can allow untrusted certificates. If the hosting company says nothing about this, you can assume that you do not have to allow untrusted certificates.

Hosting companies that support one-click publish typically provide this information in an email that is sent to you after you sign up for an account. If you do not receive such an email automatically, you must request the information.

You will begin by creating a Web application project by using the Visual Studio ASP.NET Web Application template. This template creates a Web project that includes a master page, content pages, a cascading style sheet (.css) file, client script files, and membership features.

To create a Web project to deploy

  1. In Visual Studio, from the File menu, select New Project to open the New Project dialog box.

    NoteNote

    Make sure that you select New Project and not New Web Site. One-click publish works only with Web application projects.

  2. In the Installed Templates window, expand Visual Basic or C# and select Web.

  3. Select the ASP.NET Web Application template.

    The New Project dialog box resembles the following illustration:

    New Project dialog box with default values
  4. Click OK.

    Visual Studio creates the Web application. The App_Data folder is created for the membership database, but there is no database in it yet.

    The following steps assume that the name of the application is WebApplication1.

  5. In Solution Explorer, expand the Account folder, right-click the Register.aspx file, and then select View in Browser.

    The Create a New Account page appears, as shown in the following illustration:

    Create A New Account page
  6. Enter newuser for User Name, enter newuser@webapplication1.com for E-mail, enter a password, and then click Create User. Make a note of your password, because you must enter it later.

    An ASPNETDB.MDF SQL Server database file is created in the App_Data folder, and the values that you have provided are entered into it.

  7. Close the browser.

By default, the active build configuration for new projects is Debug. This walkthrough illustrates how to deploy to a public Web site. Therefore, you will switch to the Release build configuration and then create deployment settings for that build configuration.

To set the active build configuration

  1. In the Build menu, click Configuration Manager.

    The Configuration Manager dialog box is displayed.

  2. In the Active solution configuration drop-down list, select Release.

  3. The Active solution configuration list is typically displayed on the main toolbar. If it is displayed there, you can change the build configuration without opening Configuration Manager.

  4. Close Configuration Manager.

In the following procedure, you specify which files and IIS settings to deploy. You do this by using the Package/Publish Web tab of the project's Properties page.

To specify which files and IIS settings to deploy

  1. In Solution Explorer, right-click the project and then select Properties.

    The Properties page is displayed.

  2. Select the Package/Publish Web tab.

    The Package/Publish Web tab is displayed, as shown in the following illustration:

    Package Publish Web tab
  3. In the Configuration drop-down list, make sure that Active (Release) is selected. By default, the active build configuration is selected, and in the previous procedure you set the active build configuration to Release.

  4. In the Items to deploy (applies to all deployment methods) drop-down list, make sure that Only files needed to run this application is selected. (This is the default value.)

    For more information about how Visual Studio determines which files to deploy, see the question "Why don't all of the files in my project folder get deployed?" in ASP.NET Web Application Project Deployment FAQ.

  5. Select the Exclude generated debug symbols check box.

    Typically, you do not run public Web sites in debug mode.

    NoteNote

    The ability to run a deployed site in debug mode depends on this option and on a Web.config file setting. It does not depend on the name of the build configuration.

  6. Select the Exclude files from the App_Data folder check box.

    The project uses a SQL Server Express .mdf file in the App_Data folder for the membership database. However, one-click publish will deploy the database by generating and running scripts, using the destination connection string. Therefore, you will not deploy the .mdf file.

  7. Make sure that the Include all databases configured in Package/Publish SQL tab check box is selected. (You will configure the Package/Publish SQL tab in the following procedure.)

    Save the changes to the Package/Publish Web tab.

In the following procedure you specify which SQL Server scripts should run during deployment. You do this by using the Package/Publish SQL tab.

To specify which SQL Server scripts run during deployment

  1. Click the Package/Publish SQL tab.

    The Package/Publish SQL tab is displayed, as shown in the following illustration:

    Package/Publish SQL tab
  2. Click the Import from Web.config button.

    A row is created in the grid that has the name "ApplicationServices-Deployment".

  3. Make sure that the ApplicationServices-Web.config line in the Database Entries table is selected.

    The fields below the Database Entries grid apply to the selected row in the Database Entries grid. If no row is selected, the fields below the table are disabled.

  4. In the Connection string for destination database box, enter the connection string that you received from the hosting company.

  5. Make sure that the Pull data and/or schema from an existing database check box is selected.

    When you clicked the Import from Web.config button, this option was automatically selected. The Connection string for the source database box was automatically filled in using the connection string from the Web.config file.

  6. Set the Database scripting options drop-down list to Schema and Data.

    This causes the sample membership record that you entered earlier to be deployed with the database. This makes sure that you will be able to log in to the public site using the newuser credentials that you entered in the development site.

  7. Save the changes to the Package/Publish SQL tab.

In the following procedure you create a transform file that causes the database connection string in the deployed Web.config file to be set to the correct value.

To update the connection string in the Web.config file by creating a transform file

  1. In Solution Explorer, expand the Web.config file.

  2. If a file that is named Web.Release.config is not present, right-click the Web.config file and then select Add Config Transforms.

  3. Open the Web.Release.config file.

  4. Delete the block of comments that contains a connectionStrings element.

  5. Insert the following markup in its place. (Replace [connection string] with the connection string that you received from the hosting company.)

    <connectionStrings>
      <add name="ApplicationServices"
           connectionString="[connection string]"
           providerName="System.Data.SqlClient" 
           xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
      </connectionStrings>
    
  6. Save and close the Web.Release.config file.

In the Publish Web dialog box, you create a publish profile that specifies how and where the project should be deployed. You can create different profiles that have different settings. Profiles are independent of build configuration. That is, any publish profile can be used with any build configuration. For example, you might want one profile for deploying to a local server and a different one for deploying to a hosting company. You could first use the local server profile with the Release build configuration to verify that deployment is successful with your Release deployment settings. You could then you use the hosting-company profile to publish to the public Web site. There is a limit of 50 publish profiles.

To create a publish profile

  1. From the Build menu, select Publish WebApplication1.

    The Publish Web dialog box is displayed using "Profile1" as the default profile name, as shown in the following illustration:

    Publish Web dialog box
  2. In the Publish method drop-down list, make sure that Web Deploy is selected.

  3. In the Service URL box, enter the value that you received from the hosting company.

  4. In the Site/application box, enter the value that you received from the hosting company.

  5. Clear the Leave extra files on destination check box.

    After the initial deployment, this specifies that if you delete files in the Web project and then redeploy the project, those files will also be deleted from the hosting company's server. In other words, when this option is set, the deployment process synchronizes the files on the destination server so that they reflect only the files that are part of the deployment.

  6. Select the Mark as IIS application on destination check box.

  7. If the hosting company advises you to allow untrusted certificates, select the Allow untrusted certificate check box. Otherwise, leave this check box cleared.

  8. In the User name and Password boxes, enter the credentials that were provided by the hosting company.

  9. Select the Save password check box.

    The password is saved in encrypted form in an .xml file in the project folder.

  10. Click the Save button to save the profile and then close the dialog box.

Now that all the preparation is complete, in order to deploy you just click the Publish button on the Publish Web dialog box or on the Web One Click Publish toolbar. In this walkthrough, you will publish multiple times. You will make sure that the Web One Click Publish toolbar is shown so that you can use the Publish button whenever you want to deploy.

To deploy the application and verify that deployment was successful

  1. Right-click the main toolbar and make sure that Web One Click Publish is selected.

    The Web One Click Publish toolbar is displayed, as shown in the following illustration:

    One-click publish toolbar
  2. In the Web One Click Publish toolbar, click the Publish button.

    The project is deployed to the hosting company's servers. The Visual Studio Output window displays the progress of the deployment, as shown in the following illustration:

    Output window after one-click publish
  3. Test the application by going to the public URL that points to it.

    The Default.aspx page is displayed, as shown in the following illustration:

    Default.aspx page after deployment
  4. Click the Log In link.

    The Log In page appears, as shown in the following illustration:

    Log In page
  5. Enter newuser for the Username, enter the password that you used when you created the newuser account, and then click the Log In button.

    The Default.aspx page is displayed again. This time, Welcome newuser! is displayed next to the Log Out link, as shown in the following illustration:

    Default.aspx page after logging in

    This verifies that the database and the Web pages were successfully deployed.

Now that the project has been deployed, you can make changes to the site and then click the Publish button again. Visual Studio automatically determines what has changed and uploads only the changes. However, Visual Studio does not automatically find changes in database structure or data. You must clear a check box in order to prevent Visual Studio from trying to create database tables again.

In the following procedure, you make a change to the Web application that does not include a database change.

To make a change to the application

  1. Open the About.aspx file.

  2. Delete the text "Put content here" and replace it with the text "Welcome to WebApplication1."

  3. Save the file.

You will now change database deployment settings to make sure that Visual Studio does not redeploy the database.

To turn off database deployment

  1. In Solution Explorer, right-click the project and then click Properties.

    The Properties page is displayed.

  2. Select the Package/Publish Web tab.

  3. Clear the Include all databases configured in the Package/Publish SQL tab check box.

Now you can redeploy the project. Visual Studio will determine what has changed and will upload only the changes. No database scripts will be run.

To deploy the application and verify that deployment was successful

  1. In the Web One Click Publish toolbar, click the Publish button.

    The changed About.aspx file is deployed to the hosting company's servers. The Visual Studio Output window shows that no database scripts run during deployment, as shown in the following illustration:

    Output window after redeployment
  2. Test the application by going to the public URL that points to it.

  3. Click the About tab on the Default.aspx page.

    The browser displays the About page that includes the new text that you added in the previous procedure, as shown in the following illustration:

    About page showing changed text
    NoteNote

    You do not have to confirm that database was not deployed. If you did not disable updates to the database, the second deployment would have failed, because the scripts would have tried to create objects that already exist.

In this walkthrough you deployed a Web application that uses a database, and then you deployed a change to the Web application that did not involve a database change. Some other typical deployment tasks that you might want to perform include the following:

  • Change settings in the Web.config file other than database connection strings.

  • Put a connection string in the deployed Web.config file that differs from the one that is used to deploy the database. (Typically, the Web application can use credentials that have fewer permissions than the deployment process needs.)

  • Deploy multiple databases.

  • Deploy updates to database structure or data.

For information about how to perform these tasks, see Walkthrough: Deploying a Web Application Project Using a Web Deployment Package (Part 1 of 4). The instructions for how to set up the Package/Publish Web and the Package/Publish SQL tabs are the same for one-click publish as they are for deploying an application by using a package.

For more information about how to deploy ASP.NET Web application projects, see ASP.NET Deployment Content Map.

Community Additions

ADD
Show:
© 2014 Microsoft