Conclusion

 

Deploying a Web Forms Application

After you create a Web Forms application and configure IIS, the next step is to deploy your application. You do this in one of three ways. The first option is to just copy the files from the development machine to the deployment machine. This is often called XCopy deployment, because the command-line XCopy utility is sometimes used for this kind of deployment. The other options are to use Microsoft Visual Studio to copy the Web site, or to create a setup program that installs the application.

Each of the following explanations assumes that your Web site will be deployed on a machine that is running IIS. I will be using the World Wide Web service for these examples.

Deploying an Application Using XCopy Deployment

When you want to deploy an application to a new server, you can often just copy the entire folder to the new server, and then create the virtual application using the methods described in the previous section. When you look at a Web application folder from your development machine, you will likely see files with .aspx, .aspx.cs, and .config file extensions. For example, Figure A-14 shows the folder with some of the sample applications used in this book.

image from book
Figure A-14: The SampleWebApplication folder in Windows Explorer

Copying all files is often the simplest solution, especially after IIS is configured. The copying can take place literally using xcopy from the command prompt, or (more commonly) using Windows Explorer or a tool that allows File Transfer Protocol (FTP) transfers.

If you are moving the application to a server on which you do not want to deploy source code, you can precompile the application, and then deploy only placeholder files (described in a moment) and a .dll file with the compiled code. For instance, using the following line from a command prompt running on the Web server creates a compiled version of the application in the server's c:\projects\test folder.

ASPNET_Compiler.exe -v /SampleWebApplication c:\projects\test 

The folder will be created if it does not already exist, with the files shown in Figure A-15. This folder need not be configured in IIS.

image from book
Figure A-15: The compiled version of the SampleWebApplication folder in Windows Explorer

Note that the .aspx files shown in Figure A-15 do not contain the actual markup code from our original application; they are simply placeholders so that ASP.NET knows which pages the application makes available to your users. They don't contain any markup, as you might have gathered by examining the file sizes shown in Figure A-15, which are abnormally small. The markup that was originally in the .aspx files is compiled, and files with an extension of .compiled are placed in the bin folder.

ASPNET_Compiler.exe is a program included with the .NET Framework that precompiles all files that are part of an ASP.NET application. In addition to allowing deployment of an application without source code and markup to protect your code, precompiling the application eliminates the delay that can be present when an application is accessed for the first time. An implication of compiling the pages using ASPNET_Compiler.exe is that you cannot change the markup on an .aspx file without going back to the original version of the site, editing the .aspx file, and then recompiling the site. But perhaps more importantly, the .aspx.cs files are not in the target folder specified on the command line. The bin folder contains a .dll file for the site, as well as files with an extension of .compiled for each of the .aspx files in the application. For more information, search the MSDN documentation for ASPNET_Compiler.exe.

Deploying an Application Using Visual Studio

Another option for copying an application from the development machine to another server for deployment is to use the Copy Web Site option in Visual Studio. Click Copy Web Site on the Website menu in Visual Studio to open a screen similar to the one shown in Figure A-16.

image from book
Figure A-16: The Copy Web site screen in Visual Studio

Figure A-16 shows all the files and folders in the local project on the left side of the screen. The right side is blank. To select the destination for the copy of the Web site, click Connect. You should see a dialog box similar to the one shown in Figure A-17.

image from book
Figure A-17: The Open Web Site dialog box

The left pane of the Open Web Site dialog box allows you to copy to one of four types of destinations. The first is File System. Click File System, and you will be able to navigate to a folder on the local file system or a networked drive.

The second type of destination (and the default, presuming IIS is running on your machine) is Local IIS. Although it is not initially obvious (it was not to me), in the upper-right section of the dialog box, the left-most of the three icons allows you to create a new Web site. Click the Create New Web Application icon, and a new Web site folder appears in the tree view of the local IIS system, as shown in Figure A-18.

image from book
Figure A-18: Creating a new Web application in the Local IIS

This feature works like the New Folder option in Windows Explorer. Figure A-19 shows the screen that results after I change the name of the folder to Destination and click Open.

image from book
Figure A-19: Files in the Destination folder that can be copied form the source site to a remote site

Selecting all files and then clicking the right arrow button moves all selected files to the newly created virtual application on your local IIS.

If you look back at Figure A-17, you will see that below the Local IIS destination option is the FTP Site option. The FTP Site option allows you to use FTP to send files from the local machine to any server with a running FTP server that is accessible to your current machine. The final option, Remote Site, is similar to the Local IIS option, but the destination server must be running Microsoft FrontPage Server Extensions.

Deploying an Application Using a Web Setup Project

The final option for deploying a Web application is to create a setup application. On the File menu in Visual Studio, click New, and then click Project. In the dialog box that appears, expand Other Project Types, and then expand Setup And Deployment. Click the Web Setup Project template (presuming it is available to you; it may not be available in all versions of Visual Studio), and the dialog box that appears should be similar to the one shown in Figure A-20.

image from book
Figure A-20: The New Project dialog box, with Web Setup Project selected

In the Solution list, select Add To Solution, and then click OK. On the screen that appears (shown in Figure A-21), right-click Web Application Folder, click Add on the menu that appears, and then click Project Output.

image from book
Figure A-21: The newly created Web Setup Project in Visual Studio

If the solution contains only a single Web application (as the SampleWebApplication solution does), a dialog box similar to Figure A-22 appears.


Figure A-22: Selecting project output in Web Setup Project

Click OK to add the project output to the Web setup output. On the Build menu in Visual Studio, click Build WebSetup1. The Web setup project is built, containing the output from the Web application. When you navigate to the Debug folder under the project folder, you should see the Setup.exe and WebSetup1.msi files, as shown in Figure A-23.

image from book
Figure A-23: The output from a Visual Studio Setup project

If you run Setup.exe, the setup program walks you through installation of the Web application. One of the screens allows you to specify the name of the virtual folder in which the Web application should be installed. The setup program creates the virtual directory in IIS. By right-clicking Web Application Folder (shown in Figure A-21) and then selecting Properties, you can specify options for the setup project, including the default name of the virtual folder used by the setup program.

Which Deployment Option Is Right for You?

Which deployment option you should use depends on a variety of factors. If you must deploy to a remote server, and the only access to that remote server is via FTP (a situation that is common when you are paying for a site on a shared server), you must either use an FTP program outside of Visual Studio or use the Copy Web Site option in Visual Studio. If the destination server has FrontPage Server Extensions installed, using the Remote Site destination in the Copy Web Site option in Visual Studio is a reasonable option. If the application must be installed by another user, who might not be familiar with ASP.NET applications, creating a Web setup program should allow a user unfamiliar with IIS to install the application. Just as important, if your application has any unusual requirements and must be installed on many different servers, the Web setup program should allow repeated installs to be performed in a consistent manner.

In many cases, becoming familiar with IIS and manually deploying the Web application might be the easiest option, in the long run.

 


Programming Microsoft Web Forms
Programming Microsoft Web Forms (Pro Developer)
ISBN: 0735621799
EAN: 2147483647
Year: 2005
Pages: 70
Authors: Douglas J. Reilly
BUY ON AMAZON

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