Microsoft ASP. NET site deployment guide (5): deployment to IIS as a test environment

Source: Internet
Author: User

1. Summary

During program Development, we usually test in Visual Studio. By default, we use Visual Studio Development Server (Cassini). This makes Development and testing easier, however, it may not work properly on IIS. Therefore, the result may be running normally in Visual Studio, but once deployed on IIS, an error occurs.

You can use the following methods to test to ensure that your program is okay:

  1. During Development, use IIS Express or the official version of IIS to replace the default Visual Studio Development Server to test the program. This ensures that there are few problems in IIS. However, this method cannot test whether your deployment process is correct or verify the deployment structure.
  2. Deploy the program to IIS on your development machine, and then deploy the program to the production environment in the same step to verify whether your deployment process and running in the production environment are successful.
  3. Deployment to a test environment close to the production environment. Because the production environment is a third-party provider, the ideal test environment is that the provider opens a second account (for testing purposes only ), in this way, you can use the same deployment steps as the formal production environment.

This section demonstrates the second method. The third method can be discussed at the end of Chapter 7. In addition, there is a resource connection address required by the first method at the bottom of this chapter.

 

Reminder: check the Troubleshooting page if an error message or some functions are abnormal during operations in this section.

2. The configuration program runs on Medium Trust.

Before installing IIS and deploying IIS, we need to modifyWeb. configFile to make the Configuration closer to the shared host environment. Host providers usually let your program run inMedium trustLevel, that is to say, some things cannot be done. For example, you cannot access the registry or read/write files from directories outside your program. The local machine runs onHigh trustThat is, some things you can do may not be done in the production environment. Therefore, to ensure that deployment to the production environment is normal, you need to change the running configuration of the test environmentMedium trust.

 

InWeb. configFile, inSystem. webAdd the <trust> element to the element node, as shown below:

<configuration>  <!-- Settings -->  <system.web>    <trust level="Medium"/>    <!-- Settings -->  </system.web></configuration>

 

Now the program can run inMedium trustSo that you can find the error that requires high trust to run as soon as possible.

3. Install IIS and Web Deploy

You must first install IIS and Web Deploy to Deploy the program to IIS on your development machine. By default, these components are not installed on Windows 7. If you have already installed them, ignore this section.

We strongly recommend that you use Web Platform Installer to install IIS and Web Deploy, because the recommended configuration of IIS is automatically installed and the dependent software required for IIS and Web Deploy is automatically installed.

Use Web Platform Installer to install IIS and Web Deploy. Use the following connection. If you have installed one of them or related dependent software, the Web Platform Installer only installs the remaining parts.

  • Install IIS and Web Deploy using WebPI
4. Set the default application pool to. Net4.

After installing IIS, luck IIS Manager(START-> Run, enter inetmgr, and press Enter)Make sure that the default program pool uses the. NET Framework Version 4.

InConnection(Connections) Panel, expand server Node SelectionApplication pool(Application Pools), In the right panel, ViewDefaultAppPoolWhether the. NET framework version is v4.0. If yes, ignore this section.

 

If you can only see two application pools, all of which are. NET Framework 2.0, you need to install ASP. NET 4 in IIS and then configure IIS for use.

Open a command prompt window, right-click and select Run as Administrator (Run as administratorthen, then Run aspnet_regiis.exe to install ASP. NET 4 to IIS. Run the following command:

cd %windir%\Microsoft.NET\Framework\v4.0.30319aspnet_regiis.exe –iru

The above name will create two application pools for. NET Framework 4, but the default version is v2.0. Because you need to deploy the program to the application pool of. NET 4, you need to modify their version to NET 4.

Run againIIS Manager, ClickApplication pool, Re-view the right panel, clickDefaultAppPoolAnd thenOperation Panel(Actions) ClickBasic settings(Basic Settings).

 

InEdit application pool(Edit Application PoolIn the dialog box. NET Framework versionTo. NET Framework v4.0.30319And then clickOK(OK).

 

Now you can publish the program to IIS.

5. Publish to IIS

Visual Studio 2010 and Web Deploy can be deployed in the following ways:

  • Publish with Visual Studio one-click
  • CreateDeployment packageAnd then use the IIS Manager management console for installation. The deployment package is a. ZIP file that contains all the files and metadata to be deployed on IIS.
  • Create a deployment package and install it using the command line

The previous sections mentioned the three methods of automatic deployment and setting of Visual Studio. This chapter uses the first one. For more information about using Deployment packages, see ASP. NET Deployment Content Map.

Before publishing, make sure that your Visual Studio is running in administrator mode (Start Menu, right-clickVisual Studio 2010, SelectRun as Administrator).

Change the current active build configuration to Test. You can choose from the toolbar (for example) or (Build)In the menuConfiguration Manager(Configuration Manager.

Solution ExplorerRight-click the ContosoUniversity project and select publish (Publish).Publish WebDialog box.

 

Set the profile name to "Test". If the text box is not displayed, selectNewAnd enter a new name.

Service URLEnter "localhost"

Site/applicationEnter "Default Web Site/ContosoUniversity"

SelectMark as IIS application on destination. (In some cases, you do not need to deploy it on IIS. For example, the project itself is not a web program. It only contains some images and XML files. In this case, you do not have to choose one, so that no IIS program is created .)

 

Click to publish (Publish). If you receive the following message box, run Visual Studio as an administrator again.

 

If you disable Visual Studio, for example, when you re-open it and then publish it in a later chapter, be sure to run it as an administrator. If it is not an administrator, the publishing program tries to release the program instead of prompting an error box. Sometimes it prompts an error message with no permissions.

If it is running in administrator mode, the Output window displays the compilation and publishing success information.

 

Run the IIS manager (Connections) Panel, you can (Default Web Site).ContosoUniversityIf IIS is enabled before, click Refresh (Refresh). In (Actions) Click to browse the Panel (Browse *: 80 (http)) To verify whether you can open your homepage.

 

If no error occurs, the browser will display the home page of the Contoso University project.

 

6. Test in the test environment

Open your browser and access http: // localhost/ContosoUniversity. Run the homepage again. You can see that the identifier displayed at the top of the page is "(Test)" instead of "(Dev, this means that the Web. the transformation result of config is correct.

 

OpenStudentsThe page verifies that the deployed database contains any students:

 

OpenInstructorsThe page verifies that the data still exists in the database:

 

InStudentsSelectAdd Students, Add a student, and then you can seeStudentsA student is displayed, indicating that it has been successfully saved to the database:

 

 

SlaveCoursesMenu, selectUpdate CreditsBecause the administrator permission is required for this pageLog InPage, enter the administrator account information ("admin" and "Pas $ w0rd,Update CreditsThis shows that the administrator account created in the previous section has been correctly deployed to the test environment.

 

 

CheckElmahCheck whether the folder exists and the value contains a placeholder file. This verifies that the XML file for the folder to be deployed is successfully ignored in the previous section.

Open the Web. config file in the C: \ inetpub \ wwwroot \ ContosoUniversity directory to verify that the initialization parameter value of the Code First database is Disabled:

 

Now, you have successfully deployed the program to IIS on your development machine and tested it. This verifies that the deployment process is not just copying the program content (you can also exclude unnecessary content ), in addition, the IIS Site is successfully configured for Web Deploy. In the next section, you will test another deployment task that has not been completed: Set the write permission for the Elmah folder.

7. More information

For more information about running IIS or IIS Express in Visual Studio, see the resources listed below:

  • IIS Express Overview
  • Introducing IIS Express
  • How to: Specify the Web Server for Web Projects in Visual Studio.
  • Core Differences Between IIS and the ASP. NET Development Server
  • Test your ASP. net mvc or WebForms Application on IIS 7 in 30 seconds

This post provides many examples to explain why Visual Studio Development Server (Cassini) testing is less reliable than IIS Express testing, and the reason why the test in IIS Express is not reliable in the official version of IIS.

For more information about automated Deployment tools in Visual Studio 2010 and one-click release and Deployment packages, visit ASP. NET Web Application Project Deployment Overview.

If the host provider may run the program on medium trust, visit Hosting ASP. NET Applications in Medium Trust.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.