Deploy ASP. NET Applications

Source: Internet
Author: User

Before introducing the basic principles of deploying ASP. NET applications, please understand the differences between installing Setup and deploying Deployment. Installation refers to packaging applications into easy deployment. After installation, applications can be used on the target server. Deployment is a process of obtaining an application and installing it on another machine. You may need to make some additional configurations during deployment. The following describes how to use VS. NET to deploy an application in practice. The installation will be left for future reference.

1. Use. NET "Copy project" function deployment-source code method, in. NET, you can directly Copy the source code to the target server. In Solution Explorer, you can see a "Copy Web Site" tool button reference:

Click the modify button to open the Copy Web Site window in VS. NET, as shown in.


The entire internal form is roughly divided into two parts: Source Web site: current local Web application resources, remote Web site displays Remote Web application resources, that is, the location of the target file to be uploaded)
However, you may have seen that the Remote Web site is gray and cannot be used. Therefore, you need to connect to the Remote server.

In the Copy Web Site tool column, there is a Connect button that appears after clicking the connection option, which is exactly the way to open the Web, a little difference is that you are here to deploy ASP.. NET application. Now you can use your network service provider to remotely log on to your account. As shown in the figure, you can log on to the web server in the LAN and the location to be uploaded is in the www folder.
Once the login is successful, ASP can be deployed. NET application. After you select a file, you can synchronize the files on the local server and remote server. Note that the file is "synchronized" instead of a simple copy. This advantage is that when you are local or remote, files on both sides can be updated synchronously after synchronization.


2. Use Public Web Site to deploy ASP. NET Applications-source code + binary
You can use the Public Web Site provided by VS. NET to deploy pre-compiled applications. This is similar to ASP. NET1.1. To start the public web site, select "Public Web Site" from the Build menu of VS. NET. This will pop up the Public Web Site dialog box, refer


In this region, you need to enter the remote server address, which can be HTTP or FTP. Here we use the local machine as the test and enter http: // localhost, this will create the MyFirstPage project in the current IIS home directory. The following check boxes are described as follows:
◆ Allow this precompiled site to be updatable: this option allows *. aspx not to be compiled into the report set, that is, after selecting this option, you can change the page tag.
◆ Use fixed naming and single page assemblies: This option runs the code for precompiling a specific file name.
◆ Enable strong naming on precompiled assemblies: This option requires that the renamed assembly be generated. The default value is used here. Click "OK". After compilation, you can find these pre-compiled files in the main directory of IIS.
If you open MyPage. aspx, the Code is as follows:

 
 
  1. <%@pagelanguage="C#"autoeventwireup="true"inherits="MyPage,App_Web_jmvb-kmt"%> 
  2.  
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  4.  
  5. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 
  6. <headrunatheadrunat="server"> 
  7. <title>UntitledPage</title> 
  8. </head> 
  9. <body> 
  10. <formidformid="form1"runat="server"> 
  11. <div> 
  12. Enteryourname:<asp:TextBoxIDasp:TextBoxID="nameTextBox"runat="server"/><br/> 
  13. <asp:ButtonIDasp:ButtonID="enterButton"runat="server"  
  14. Text="Enter"OnClick="enterButton_Click"/>&nbsp;<br/> 
  15. <asp:LabelIDasp:LabelID="messageLabel"runat="server"Text="Label"></asp:Label> 
  16. </div> 
  17. </form> 
  18. </body> 
  19. </html> 

As mentioned above, since the Page command is <% @ page language = "C #" autoeventwireup = "true" inherits = "MyPage, App_Web_jmvb-kmt" %> does not contain CodeFile, so this compilation method and ASP. NET1.1 compatibility.
The inherits of the Page directive specifies that the class set of MyPage. aspx is MyPage and Assembly set App_Web_jmvb-kmt. In other words, when the system does not load the Page, it will load the MyPage class to the App_Web_jmvb-kmt.dll under the bin folder as the Page class of the MyPage. aspx background file.

3rd use aspnet_compiler.exe to deploy the application
Aspnet_compiler.exe is ASP. A new command added by NET2.0. the. NET Framework is unavailable. You can find this file in the installation directory, for example, c: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 directory.

Aspnet_compiler.exe provides many parameters. You can enter Aspnet_compiler.exe /? View the meaning of these parameters. Here we will introduce several parameters used for query:

1. The-m parameter tells the system to configure the application using IIS metadata, for example, the following command
Aspnet_compiler-m/LM/W3SVC/1/Root/MyApp c: \ MyTarget
/LM/W3SVC/1/Root indicates the configuration information of the HTTP service to be used in/LM/W3SVC, in the control panel, there is a "Server Extensions manager ". You can enable the configuration of your local machine. In this command, it indicates that the current application is MyApp, and the physical path of the file used by this application is c: \ MyTarget.

2-vv indicates the virtual path of the application. If it is used together with the-p parameter, the-p parameter specifies the physical path. Otherwise, the IIS Element Data configuration is used. The default value is the current site of the application.
The following command and the above registration.
Aspnet_compiler-v/MyApp

The following does not rely on IIS configuration because it displays the physical path of the declared application.
Aspnet_compiler-v/MyApp-p c: \ myapp c: \ MyTarget

-U
V virtualPath-Virtual Path of the application
-P physicalPath-Application Event Location

TargetDirectory-target location

Another parameter is u, which tells the compiler to keep the *. aspx page for future updates. This is the form of the "Assembly set + binary" code described above.
Next we will introduce how to use this command, and further introduce the deployment changes from ASP. NET1.1 to ASP. NET2.0.
The following code deploy an ASP. NET application using aspnet_compilier:
I used VS. NET2005's built-in server and File System to create the MyFirstPage project under My Documents C: \ Documents ents and Settings \ liwanbao \ My Documents \ Visual Studio 2005 \ WebSites.
Now I want to deploy the program to the local IIS server provider. on the IIS server, my application name is DeplayApp, and the actual path to which the application directs is D: \ DeplayMyFirstPage, therefore, if you open IIS, you will see the following effects:

In this case, the following three parameters are used to introduce aspnet_compiler.exe.

DeplayApp is the virtual path of the application, that is, the path specified by the-v parameter above.

D: \ DeplayMyFirstPage is the actual physical path corresponding to the virtual path, that is, the target path to which I want to deploy it.

C: \ Documents and Settings \ liwanbao \ My Documents \ Visual Studio 2005 \ WebSites path is the source code position of My development project.

In the command, first set pathpattern to indicate to aspnet_compiler.exe to prevent the system from finding this command. The specific command is
Aspnet_compiler-v/DeplyApp-p MyFirstPage d: \ DeplayMyFirstPage

This will generate the required file in the D: \ DeplayMyFirstPage directory *. aspx), you can find the database file of the application in App_Data directory. Note that when the database is referenced, the current location of the App_Data file is applied. For example, if the database connection is

 
 
  1. <add name="DotNetEntry_DataConnectionString1" connectionString="Data Source=.\
    SQLEXPRESS;AttachDbFilename=|DataDirectory|\DotNetEntry_Data.MDF;…  /> 

At this time, the system will automatically deploy the database under the project App_Data to the target, and if the above Code is changed:

 
 
  1. <add name="DotNetEntry_DataConnectionString1" connectionString="Data Source=.\
    SQLEXPRESS;AttachDbFilename=C:\DotNetEntry_Data.MDF;…  /> 

Because the absolute location of DotNetEntry_Data.MDF is specified, the target file does not protect the bin folder of the App_Data file from storing the compiled DLL file, but also contains references to the Assembly, for example, use NotePad to open default. aspx. cdcab7d2. compiled, similar code:

 
 
  1. <?xmlversionxmlversion="1.0"encoding="utf-8"?> 
  2. <preserveresultTypepreserveresultType="3"virtualPath="/DeplayApp/Default.
    aspx"hash="fffffff5007efec4"filehash="6c5c681005a7e96b"flags="110000"
    assembly="App_Web_r8n0o27x"type="ASP.default_aspx"> 
  3. <filedeps> 
  4. <filedepnamefiledepname="/DeplayApp/Default.aspx"/> 
  5. <filedepnamefiledepname="/DeplayApp/Default.aspx.cs"/> 
  6. </filedeps> 
  7. </preserve> 

If you open the *. aspx page, you can see that the content on the page is This is a marker file generated by the precompilation tool, and shocould not be deleted!

You may ask why the *. aspx file is required for all DLL files? These files have no specific content, will they be redundant? To understand this problem, you need to go to IIS. In other words, this is no longer the work scope of ASP. NET2.0. For client requests, IIS first checks whether the file you requested does not exist based on the ing. If the file does not exist, it directly prompts that the file you requested is not found. The preceding section describes how to deploy ASP. NET applications.

  1. Analysis of Theme functions in ASP. NET development skills
  2. ASP. NET Dynamic Compilation
  3. Analysis on ASP. NET supported by Apache
  4. Introduction to ASP. NET Server standard controls
  5. Analysis on SQL Server Database Backup Recovery in ASP. NET

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.