Home > Articles > Programming > Windows Programming

📄 Contents

  1. Configuring Your ASP.NET Solutions
  2. Deploying Your ASP.NET Applications
  3. Summary
This chapter is from the book

This chapter is from the book

Deploying Your ASP.NET Applications

Deploying ASP.NET solutions is actually quite easy, even if you are using compiled components in your solution. In the past, in order to completely install Web solutions, you needed to have access to the Internet Information Server Manager, COM+ Services, and even have the rights to update the registry. This was made even more difficult if you needed to deploy your solution on one or more remote servers.

Now, with ASP.NET, you can simply create the target folder(s) and copy the files directly to the target. If you have compiled components in your solution, you only need to be sure to place them in the proper subfolder. The rest is handled by ASP.NET. There is no need to attempt to register the components using the old REGSVR32.EXE.

Even better, if you need to update these compiled components on a production server, you no longer need to stop Internet Information Server or bring down the actual machine. All you need to do is copy the new component(s) over the existing one(s) and all will be taken care of for you.

In this section, you learn how to successfully move your Web pages and components to the target server and ASP.NET is able to automatically register and update your solution components. You also learn how to create scripts that handle most all of these tasks remotely.

TIP

If you are using Microsoft Visual Studio.NET to build and deploy your solutions, you may not need to go into the details of creating virtual folders, and copying files to your target server. Instead you can use one of the many built-in deployment features of Visual Studio.NET.

The New Deployment Model for ASP.NET Solutions

The ASP.NET deployment model is based on simple file copy technology. This means that you don't need any special utilities or packaging tools in order to deploy ASP.NET Webs to the target server. This "minimal deployment" model is made possible by some special services running with the .NET platform. These services are smart enough to handle the process of locating and managing compiled components on the ASP.NET server. These services are so effective that you no longer need to register your components in the Windows registry at all.

The heart of this deployment model is that all DLLs for your Web need to be placed in a special folder, the BIN folder, which is a subfolder off the root folder of your solution. For example, imagine you have a root folder called DEPLOY that contains the documents DEFAULT.ASPX and SPORT.ASMX. You also have a single compiled component, called SAMPLE.DLL that is called by both the DEFAULT.ASPX and SPORT.ASMX documents (see Figure 21.2)

Figure 21.2. Sample Web files and folders.

Notice in Figure 21.2 that the SAMPLE.DLL file is in a subfolder called BIN. Since ASP.NET does not use the Windows Registry, the only way that ASP.NET can locate your custom DLLs is for you to place them in the BIN subfolder of your solution. If you fail to place them in the correct place, you'll receive a runtime error telling you that ASP.NET cannot locate your component.

This is the only requirement that ASP.NET puts on the physical layout of your solution. You can add as many folders and files as you wish to the solution as long as all compiled DLLs are always placed in the same folder.

Now that you know how easy it is to deploy compiled components, you're ready to learn the details of how you can create the folders and copy the files to both local and remote ASP.NET Web servers.

Copying the Application to the Web Server

The first step in deployment is to create the proper folders on your target ASP.NET machine and copy all the proper files from the source machine to the target machine. This can be done using a simple XCOPY command or, for remote server, you can use FTP commands. If you have a GUI file explorer, you can even use simple drag and drop steps to complete the work. The important thing to keep in mind is that you only need to copy the files to the target machine in order to properly build and register the ASP.NET solution.

The files you need to copy depend on the types of components you have in your solution. These include your ASPX (and related) files along with all images and other resource files.

Following is a list of commonly used ASP.NET files that you should deploy to your target server if they exist in your source project:

  • .ASPX: Web forms files

  • .ASMX: Web services files

  • .ASCX: user control files

  • .ASHX: ASP.NET handler files

  • .CONFIG: configuration files

  • .VB or .CS: only if they are used as code-behind files for related .ASPX pages

  • DLL: .NET compiled components (in the BIN folder)

Using an XCOPY Script

Probably the simplest way to deploy our ASP.NET solution is to use the command line program XCOPY to copy the files from your source machine to the target machine. This is a viable solution if you have a mapped drive or UNC path to the target server from the source machine.

For example, imagine you have a mapped drive Z: that represents the root of the Web server and you want to copy files from the DEPLOY folder on your machine to the TARGET folder on the Web server. Here is an example XCOPY script that can handle the task:

xcopy c:\deploy\*.* z:\target /V/Q/Y
xcopy c:\deploy\bin\*.* z:\target\bin /V/Q/Y
pause

This script first copies all the files from the DEPLOY folder of the local machine to the TARGET folder on the remote machine. Next, all the files from the DEPLOY\BIN folder are copied to the TARGET\BIN folder. Although you could actually use a single XCOPY command (xcopy c:\deploy\*.* z:\target /s) to copy all files from the source to the destination, the above command skips folders that might contain source code for components, design documents and other non-Web files. The PAUSE statement is included only to allow the user to view the results of the command line execution before dismissing the command prompt dialog box.

TIP

If you can reach the target machine via mapped drives, you can probably just use the Windows File Explorer to simply drag the proper files and folders from the source machine to the target machine.

Using FTP Services

If the target machine is not reachable via a mapped drive, you can probably use FTP services to copy the files and folders to the target location. This requires that you have a valid FTP account at the target machine, that your account has rights to write new files on the target machine, and that the target machine publish an FTP entry point for you such that you can reach the target folder.

The following listing shows a sample set of FTP commands that can move the contents of the DEPLOY and DEPLOY\BIN folders from the local machine to the remote machine.

open localhost
user aspx4devs smart
prompt off
cd target
mkdir bin
mput d:\sharedspace\aspxbook\code\038x21\deploy\*.*
cd bin
mput d:\sharedspace\aspxbook\code\038x21\deploy\bin\*.*
bye

This example uses the FTP.EXE utility that ships with the Windows operating system. There are also a number of third-party FTP tools that offer rich user interfaces and scripting tools to make this process easier.

TIP

If you have a valid FTP account that supports uploads for your Webs, you can probably use the Microsoft Internet Explorer to FTP your files to the target. Just load Microsoft Internet Explorer and enter the FTP site you wish to contact. You can then drag and drop your files into place.

Creating the Virtual Directories on the Web Server

As mentioned earlier, all ASP.NET solutions require an entry point on the Web server. This entry point is called the "virtual directory." It is the starting point for your solution. Typically, the DEFAULT.ASPX page and many other documents are placed in this folder.

Also, if your solution has one or more precompiled components, you need to place them in a folder called BIN that is located just below the root folder of the virtual directory. This will make sure that ASP.NET can locate the compiled components at runtime.

The first step is to create the folders on the target machine. Once this is done, you need to mark the starting folder of your solution as virtual directory so that Internet Information Server will be able to route user requests to your ASP.NET application.

Creating the folders is easy. You can use simple DOS commands directly or through a script. Often you can just use your Microsoft File Explorer tool to browse to the target server and add folders as needed. You can also use FTP utilities on remote servers to do the same thing.

The important point to remember is that, once you create the folders and copy the files, you need to mark the base level as a "virtual directory." You can do this a number of different ways. The three ways covered in this chapter are:

  • Using File Explorer

  • Using Internet Information Server

  • Using a WSH Script

Using File Explorer

The simplest way to create a virtual directory on your local machine is to browse to the selected folder using the Microsoft File Explorer and complete the following steps:

  1. Locate the desired folder on the machine using Microsoft File Explorer.

  2. Right click over the desired folder to view the context menu.

  3. Select 'Properties' from the context menu.

  4. When the dialog appears, select the 'Web Sharing' tab (see Figure 21.3).

  5. Click on the 'Share this folder' radio button.

  6. When the 'Edit Alias' dialog appears, verify that the proper name appears and press the OK button until you dismiss all dialogs.

Figure 21.3 shows how steps 4 through 6 would look on a Windows 2000 machine.

Figure 21.3. Using File Explorer to create a Web share on the server.

While this method is very easy, it has its limits. First, you can only do this if you are logged onto the machine locally. For example, you cannot perform this task on a shared network disk. Second, the dialogs only let you do the simplest kind of Web publishing. If you need to adjust Internet Information Server rights, apply certificates, etc. you need to use Internet Information Server Manager instead.

Using Internet Information Server Manager

Probably the most comprehensive way to create a new Web share is to use the Internet Information Server Manager utility. This very powerful utility walks you through the process of creating and managing multiple Webs on multiple servers. Also, if configured properly, the Internet Information Server Manager can be used to manage any number of remote servers.

The details of creating and managing Webs with Internet Information Server Manager are beyond the scope of this book. However, all you need to do is to load the Internet Information Server Manager, expand the desired server in the left-side tree and right-click over the machine, and select "New—Virtual Directory" from the context menu. This will call up the "Virtual Directory Creation Wizard" that will walk you through the process from start to finish (see Figure 21.4).

Figure 21.4. Using Internet Information Server Manager to create a Web share.

The WSH Script

While both the File Explorer and Internet Information Server Manager solutions are valuable, sometimes you need to create a new virtual directory on several servers at a time or you wish to create the directories without having to click through all the dialogs. For that you need a scripted solution. Luckily, Internet Information Server ships with a number of management scripts to handle just such tasks.

Listing 21.4 shows the start of an example WSH script that can create the desired Web on the target machine without using any UI at all. This is especially valuable if you need to deploy your solution to a series of servers in a Web farm.

Listing 21.4. MAKETARGETWEB.VBS—Sample WSH Script to Create a Web Share

Option Explicit
dim vPath, scriptPath,vName

vName="Target" ' name of web to create

' get current path to folder and add web name to it!
scriptPath = left(Wscript.ScriptFullName, _
len(Wscript.ScriptFullName ) -len(Wscript.ScriptName))
vPath = scriptPath & vName

'call to create vDir
CreateVDir(vPath)

'code taken from mkwebdir.vbs and changed for single vDir creation.
Sub CreateVDir(vPath)

  Dim vRoot,vDir,webSite
  On Error Resume Next

  ' get the local host default web
  set webSite = findWeb("localhost", "Default Web Site")
  if IsObject(webSite)=False then
    Display "Unable to locate the Default Web Site"
    exit sub
  else
    'display webSite.name
  end if

  ' get the root
  set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root")
  If (Err <> 0) Then
    Display "Unable to access root for " & webSite.ADsPath
    Exit sub
  else
    'display vRoot.name
  End IF

  ' delete existing web if needed
  vRoot.Delete "IIsWebVirtualDir",vName
  vRoot.SetInfo
  Err=0 ' reset error 

  ' create the new web
  Set vDir = vRoot.Create("IIsWebVirtualDir",vName)
  If (Err <> 0) Then
    Display "Unable to create " & vRoot.ADsPath & "/" & vName & "."
    exit sub
  else
    'display vdir.name
  end if

  ' set properties on the new web 
  vDir.AccessRead = true
  vDir.Path = vPath
  vDir.Accessflags = 529
    VDir.AppCreate False
  If (Err <> 0) Then
    Display "Unable to bind path " & vPath & " to " & _ 
vRoot.Name & "/" & vName & ". Path may be invalid."
    exit sub
  end If

  ' commit changes
  vDir.SetInfo
  If (Err <> 0) Then
    Display "Unable to save changes for " & vRoot.Name & "/" & vName & "."
    exit sub
  end if

  ' report all ok
  WScript.Echo Now & " " & vName & " virtual directory " & vRoot.Name & "/"
   & vname & " created successfully."
End Sub

The script in Listing 21.4 is just the top-most routines of a much longer script. It is not important to understand all the details of this script. Instead, it's important to know that you can create a fully scripted solution for creating virtual directories on target servers.

Handling Component Registration, Versioning, and Replacement

Once you have your ASP.NET Web deployed and running in production, you're bound to discover that you need to update one or more documents or components on the production server. In the past, this meant that you needed to stop the Internet Information Server service on the machine. Sometimes you even needed to re-boot the server itself before you could complete your updates.

However, ASP.NET allows you to update both pages and compiled components without stopping any services on the machine at all. If you have new documents or DLLs to place on the production machine, all you need to do is perform an XCOPY or FTP PUT command to place the new files on the server. Once ASP.NET detects that you have placed new files on the server, the runtime services will flush the old components from memory and load the new components instead. From that point on, all site users will see the new pages and components.

ASP.NET is even smart enough to maintain a copy of the old components as long as there is at least one site visitor running the old components. In other words, when you copy new files over old, ASP.NET will not simply drop any existing users and cancel their sessions. Instead, ASP.NET will maintain existing user's paths through the old components until their current HTTP request is completed. At the same time, ASP.NET will route all new HTTP requests to the updated components. Once all existing HTTP requests are drained from the old components, these old files will be removed from memory and deleted from the machine.

This means you can safely update both pages and compiled DLLs on your production machine with minimum disruptions to your users.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020