Application Deployment

 

Application Deployment

Installing a .NET application in general, and an ASP.NET application in particular, is a matter of performing an XCopy that is, a recursive copy of all the files to the target folder on the target machine. Aside from some inevitable emphasis and promotion, the XCopy deployment expression, which is often used to describe setup procedures in .NET, communicates the gist of .NET deployment: you don't need to do much more than copy files. In particular, there's no need to play with the registry, no components to set up, and no local files to create. Or, at least, nothing of the kind is needed just because the .NET Framework mandates it.

XCopy Deployment

The deployment of a Web application is a task that can be accomplished in various ways depending on the context. As far as copy is concerned, you can use any of the following: FTP transfer, any server management tools providing forms of smart replication on a remote site, or an MSI installer application. In Visual Studio .NET 2005, you can even use the Copy Web Site function that we discussed earlier in this chapter.

Each option has pros and cons, and the best fit can only be found once you know exactly the runtime host scenario and the purpose of the application is clearly delineated. Be aware that if you're going to deploy the application on an ISP host, you might be forced to play by the rules (read, "use the tools") that your host has set. If you're going to deliver a front end for an existing system to a variety of servers, you might perhaps find it easier to create a setup project. On the other hand, FTP is great for general maintenance and for applying quick fixes. Ad hoc tools, on the other hand, could give you automatic syncup features. Guess what? Choosing the right technique is strictly application-specific and is ultimately left to you.

Copying Files

FTP gives you a lot of freedom, and it lets you modify and replace individual files. It doesn't represent a solution that is automatic, however: whatever you need to do must be accomplished manually. Assuming that you have gained full access to the remote site, using FTP is not much different than using Windows Explorer in the local network. I believe that with the Copy Web Site functionality of Visual Studio .NET 2005 in place, the need for raw FTP access is going to lessen. If nothing else, the new Copy Web Site function operates as an integrated FTP-like tool to access remote locations.

The new copy function also provides synchronization capabilities too. It is not like the set of features that a specifically designed server management tool would supply, but it can certainly work well through a number of realistic situations. At the end of the day, a site replication tool doesn't do much more than merely transfer files from end to end. Its plusses are the user interface, and the intelligence, built around and atop this basic capability. So a replication tool maintains a database of files with timestamps, attributes, properties and can sync up versions of the site in a rather automated way, minimizing the work on your end.

Building a Setup Project

Another common scenario involves using an out-of-the-box installer file. Deploying a Web application this way is a two-step operation. First, create and configure the virtual directory; next, copy the needed files. Visual Studio .NET makes creating a Web setup application a snap. You just create a new type of project a Web Setup Project select the files to copy, and build the project. Figure 2-25 shows the user interface of the setup project.

image from book
Figure 2-25: Creating a Web setup project.

The Web Application Folder node represents the virtual directory of the new application on the target machine. The Properties box lets you configure the settings of the new virtual directory. For example, the AllowDirectoryBrowsing property lets you assign browsing permission to the IIS virtual folder you will create. You can also control the virtual directory name, application execute permissions, level of isolation, and default page. The Bin subfolder is automatically created, but you can ask the setup to create and populate as many subfolders as you need.

When you build the project, you obtain a Windows Installer .msi file that constitutes the setup to ship to your clients. The default installer supports repairing and uninstalling the application. The setup you obtain in this way which is the simplest you can get does not contain the .NET Framework, which must be installed on the target machine or explicitly included in the setup project itself.

What Else Do You Need to Do?

One of the coolest features of .NET assemblies is that they are self-describing components. An application that wants to know about the internal characteristics of an assembly has only to ask! The .NET reflection of an API is the programming interface by which a client can interrogate an assembly. This fact eliminates the need of using the registry (or any other sort of centralized repository) to track paths and attributes of binary components. Another pleasant effect of the assembly's structure is that side-by-side execution is now a snap, and ASP.NET applications take advantage of it on a regular basis. In practice, whenever you update a page, two versions of the "same" assembly live side by side for awhile without interference and conflict.

So the XCopy deployment model rocks. Is there something more you need to do to finalize the deployment of your application? Sure there is. Let's detail some additional tasks.

If you use read/write files (XML files, configuration files, Access databases), you need to grant proper writing permission to the application. Likewise, if your application or control generates temporary files, you need to make accommodations for a proper folder with proper writing permissions. These tasks must be accomplished in one way or another before the application goes live. Note that in an ISP scenario you are normally given an isolated disk subtree with full write permissions granted to the ASP.NET account. You must design your applications to be flexible enough to support a configurable path for all their temporary files.

Note 

We're not saying anything specific about database configuration here. We're simply assuming that all required databases are in place, properly working, and entirely configured. If this is not the case, you might want to add this task to the list too. The same holds true for any remote application and network services you might need, including Web services and COM+components.

Configuring the Runtime Environment

Another aspect to consider is runtime configuration. When you develop the ASP.NET code, you test it on a machine with its own machine.config file. When you deploy the application on a production box, you might not be able to restore the same settings. One possible reason is that the administrator does not want you to modify the current settings because they proved to be great for other applications. (This is especially true in an ISP host scenario.)

You can work around the issue by simply replicating any needed machine.config settings to the application's web.config. However, if you are deploying your code to a service provider, you might find that many machine.config settings have been locked down and cannot be overridden. In this case, you should ask (or more exactly, beg) the administrator to let you tweak the server's configuration in a way that suits you without hurting other applications. This normally entails creating an application-specific <location> section in the server's machine.config file.

Deploying an ASP.NET application in a Web-farm scenario poses a few extra configuration issues you must be aware of. All machine.config files in the Web farm must be synchronized to the value of a few attributes. You can achieve this in two ways, the simplest of which is packing all attribute values in the application's web.config. This approach greatly simplifies the deployment because you only have to run the setup on all machines and no other changes are needed. If any of the required sections are locked down (once more, this is likely to happen in an ISP scenario), you find yourself in the situation described previously, that of begging the administrator to create a new <location> section for you.

Note 

The <location> section can be used in both machine.config and web.config to limit Web settings to the specified application path. In a deployment scenario, the section assumes particular importance in the machine.config file and subsequently requires administrative privileges. The <location> section is normally used in a web.config file in case of a deployment with a main application and a bunch of subapplications.

Site Precompilation

As mentioned, dynamically created assemblies are placed in an internal folder managed by the ASP.NET runtime. Unless source files are modified, the compilation step occurs only once per page when the page is first requested. Although in many cases the additional overhead is no big deal, removing it still is a form of optimization. Site precompilation consists of deploying the whole site functionality through assemblies. A precompiled application is still made up of source files, but all pages and resources are fictitiously accessed before deployment and compiled to assemblies. The dynamically created assemblies are then packaged and installed to the target machine. As you can see, site precompilation also saves you from deploying valuable source files, thus preserving the intellectual property.

Important 

Source files, like C# classes or WSDL scripts, are protected against HTTP access. However, they are at the mercy of a hacker in the case of a successful exploitation that allows the attacker to take control of the Web directories.

Site precompilation was possible in ASP.NET 1.x, but in version 2.0 it has the rank of a system tool, fully supported by the framework. In summary, site precompilation offers two main advantages:

Precompilation can take two forms: in-place precompilation and deployment precompilation.

Note 

To protect intellectual property, you can also consider obfuscation in addition to site precompilation. Obfuscation is a technique that nondestructively changes names in the assembly metadata, thus preventing potential code-crackers from scanning your files for sensitive strings. Obfuscation does not affect the way the code runs, except that it compacts the executable, making it load a bit faster. If decompiled, an obfuscated assembly generates a much less readable intermediate code. Although applicable to all .NET applications, there is nothing wrong with obfuscating your ASP.NET assemblies in case of hacker access for the very same reasons. Visual Studio .NET 2005 provides the community edition of a commercial tool Dotfuscator.

In-Place Precompilation

In-place precompilation allows a developer or a site administrator to access each page in the application as if it were being used by end users. This means each page is compiled as if for ordinary use. The site is fully compiled before entering production, and no user will experience a first-hit compilation delay, as in version 1.x. In-place precompilation takes place after the site is deployed, but before it goes public. To precompile a site in-place, you use the following command, where /proaspnet20 indicates the virtual folder of the application:

aspnet_compiler _v /proaspnet20 

If you precompile the site again, the compiler skips pages that are up to date and only new or changed files are processed and those with dependencies on new or changed files. Because of this compiler optimization, it is practical to compile the site after even minor updates.

Precompilation is essentially a batch compilation that generates all needed assemblies in the fixed ASP.NET directory on the server machine. If any file fails compilation, precompilation will fail on the application.

Precompilation for Deployment

Precompilation for deployment generates a file representation of the site made of assemblies, static files, and configuration files a sort of manifest. This representation is generated on a target machine and can also be packaged as MSI and then copied and installed to a production machine. This form of precompilation doesn't require source code to be left on the target machine.

Precompilation for deployment also requires the use of the aspnet_compiler command-line tool:

aspnet_compiler -m metabasePath                 -c virtualPath                 -p physicalPath                 targetPath 

The role of each parameter is explained in Table 2-2.

Table 2-2: Parameters of the aspnet_compiler Tool

Parameter

Description

metabasePath

An optional parameter that indicates the full IIS metabase path of the application

virtualPath

A required parameter that indicates the virtual path of the application

physicalPath

An optional parameter that indicates the physical path of the application

targetPath

An optional parameter that indicates the destination path for the compiled application

If no target path is specified, the precompilation takes place in the virtual path of the application, and source files are therefore preserved. If a different target is specified, only assemblies are copied, and the new application runs with no source file in the production environment. The following command line precompiles ProAspNet20 to the specified disk path:

aspnet_compiler -v /ProAspNet20 c:\ServerPath 

Static files such as images, web.config, and HTML pages are not compiled they are just copied to the target destination.

Warning 

If you don't want to deploy HTML pages as clear text, rename them to .aspx and compile them. A similar approach can be used for image files. Note, however, that if you hide images and HTML pages behind ASP.NET extensions, you lose in performance because IIS is used to process static files more efficiently than ASP.NET.

Precompilation for deployment comes in two slightly different forms with or without support for updates. Sites packaged for deployment only are not sensitive to file changes. When a change is required, you modify the original files, recompile the whole site, and redeploy the new layout. The only exception is the site configuration; you can update web.config on the production server without having to recompile the site.

Sites precompiled for deployment and update are made of assemblies obtained from all files that normally produce assemblies, such as class and resource files. The compiler, though, doesn't touch .aspx page files and simply copies them as part of the final layout. In this way, you are allowed to make limited changes to the ASP.NET pages after compiling them. For example, you can change the position of controls or settings regarding colors, fonts, and other visual parameters. You can also add new controls to existing pages, as long as they do not require event handlers or other code.

In no case could new pages be added to a precompiled site without recompiling it from scratch.

Of the two approaches to precompilation for deployment, the former clearly provides the greatest degree of protection for pages and the best performance at startup. The option that provides for limited updates still requires some further compilation when the site runs the first time. In the end, opting for the deployment and update in ASP.NET 2.0 is nearly identical to the compilation and deployment model of ASP.NET 1.1, where .aspx files are deployed in source and all classes (including code-behind classes) are compiled to assemblies.

 


Programming Microsoft ASP. Net 2.0 Core Reference
Programming Microsoft ASP.NET 2.0 Core Reference
ISBN: 0735621764
EAN: 2147483647
Year: 2004
Pages: 112
Authors: Dino Esposito
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net