How to Test and Debug an ASP.NET 2.0 Application

In this article, you will learn how to create a website that runs under IIS for testing purposes. You will also learn how to create and test a file-system website with the ASP.NET Development Server. It is excerpted from chapter four of the book Murach's ASP.NET 2.0 Web Programming with VB 2005, written by Joel Murach and Anne Boehm (Murach, 2006; ISBN: 1-890774-32-4).

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 15
May 11, 2006
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

How to create ASP.NET web sites that run under IIS

In chapter 2, you learned how to create a file-system web site that runs under the ASP.NET Development Server. If you have access to an IIS web server, though, you may want to create a web site that runs under IIS so you can test the web site in that environment. Or, you may want to create and test a file-system web site with the ASP.NET Development Server first, and then test it under IIS later.

How to create a local IIS web site

A local IIS web site is a web site that resides on your local computer. To create a local IIS web site, then, you must have IIS installed on your computer. Please see appendix A for information on how to install IIS.

Figure 4-1 illustrates how you create a local IIS web site. To start, you select HTTP for the location option in the New Web Site dialog box (see the next figure). Then, you typically click the Browse button to display the Choose Location dialog box shown in this figure.

In the Choose Location dialog box, you can click the Local IIS button at the left side of the dialog box to display the IIS web server. Then, you can select the directory where you want to create your web site. In this case, I selected the ASPNET2005 directory. Then, I clicked the Create New Web Application button to create a new web site named Ch03Cart in that directory.

When you use this technique, the files for the web site are stored within the directory you create. If that’s not what you want, you can create a virtual directory that points to the directory where the files for the web site will be stored. To do that, just click the Create New Virtual Directory button in the Choose Location dialog box. Then, a dialog box is displayed that lets you enter a name for the virtual directory and the path where the files for the web site should be stored. In the dialog box shown in this figure, for example, the virtual directory will be named Ch03Cart, and the files will be stored in a directory with the same name within the ASP.NET 2.0 Web Sites directory on the C drive.

In addition to using the New Virtual Directory dialog box to create a virtual directory for a new web site, you can also use it to create a virtual directory for a file-system web site you’ve already created. To do that, just enter the path for the existing web site in this dialog box. Then, when you click the OK button in the New Web Site dialog box, Visual Studio will warn you that there is already a web site at the location you specified. To create a virtual directory that points to the existing web site, select the Open the Existing Web Site option.

Before I go on, you should realize that you can also create a virtual directory for a file-system web site using the IIS Management Console. If you’re interested, you can learn how to do that in appendix A. Unless you need to change the default permissions for a virtual directory, though, I recommend that you create the virtual directory from within Visual Studio.

The dialog box for selecting a local IIS web site

                                                


             
        Figure 4-1.  How to create a local IIS web site


The dialog box for creating a virtual directory

                                             



Description

  1. To create a web site that will run under IIS on your local computer, select HTTP for the location option in the New Web Site dialog box. Then, enter the path of the IIS directory where you want to create the web site, or click the Browse button to display the Choose Location dialog box.
  2. From the Choose Location dialog box, click the Local IIS button and expand the Default Web Site node. Then, select the directory where you want to create the web site from the default web site and click the Open button, or create a new directory or virtual directory.
  3. To create a new IIS directory for a web site, click the Create New Web Application button and then enter the name of the directory. The files for the web site will be stored in this directory.
  4. To create a virtual directory for the web site, click the Create New Virtual Directory button to display the New Virtual Directory dialog box. Enter a name for the directory and the path where you want to store the files for the web site. If the path you specify already contains a web site, you can open that web site from the virtual directory.

How to create a remote IIS web site



A remote web site is similar to a local web site except that a remote web site resides on a computer that you have access to over a LAN. To create this type of web site, FrontPage Server Extensions must be installed on the remote computer. Then, you can just select the HTTP location option and enter the location of the web site as shown in figure 4-2. Here, a web site named Ch03Cart is being created in a directory named ASPNET2005 on a server named mma1.

Although you use the same techniques to work with a remote web site as you use to work with a local web site, you should realize that the permissions for a remote web site may not be set the way you want. For example, suppose you create a web site that writes to a text file that’s stored in the App_Data folder of the site. To do that, the web site must have write permissions on that folder. By default, though, a remote web site is given only read permissions. Because of that, you’ll need to have the system administrator assign the appropriate permissions to the web site.

The dialog box for creating a remote IIS web site


Figure 4-2.  How to create a remote IIS Web site


Description

  1. To create a remote web site, select HTTP from the Location drop-down list. Then, enter the URL of the web site you want to create.
  2. You can also create a remote web site by clicking the Browse button and then using the Choose Location dialog box that’s displayed for a remote site. However, this dialog box doesn’t provide any additional options.
  3. By default, a web application that you create on a remote server doesn’t have the permissions needed to change files in the web site at runtime. If an application needs to change a file, then, you’ll need to contact the system administrator about giving it the appropriate permissions.
  4. Visual Studio communicates with a web site on a remote server using HTTP and FrontPage Server Extensions. Because of that, FPSE must be installed on the remote server. For information on how to install FPSE, see appendix A.

How to create an FTP web site

An FTP web site is a web site that resides on a remote computer and that supports FTP file transfers. In most cases, FTP web sites are hosted on a server that you have access to over the Internet. In that case, the web site may already be set up for you. If not, you can use the Choose Location dialog box shown in figure 4-3 to create a new web site.

To display this dialog box, select FTP for the location option from the New Web Site dialog box, and click the Browse button. Then, enter the name of the server where you want to create the site and the path to the directory where the files for the web site will be stored. Note that except for the final directory, all the directories in the directory path must already exist. In this example, that means that the Murach directory must already exist. That’s because this directory maps to a virtual root that must be set up on the server. The virtual root works much like an IIS virtual directory. However, it points to the location where files are transferred to and from the server.

In addition to the server name and directory path, you can specify the port that Visual Studio should use to send commands to the server, you can specify whether the connection to the server is established using active or passive mode, and you can specify whether you’re logged in as an anonymous user or an authenticated user. In most cases, you’ll leave the port set at 21. However, you may need to change the Passive Mode and Anonymous Login options.

By default, Visual Studio uses active mode to establish a connection with the FTP server. To understand how active mode works, you need to realize that two ports are required to use FTP: one to transmit commands and one to transmit data. In active mode, Visual Studio connects to the server using the command port and then passes the address of the data port to be used to the server. Then, the server connects to Visual Studio using the data port.

The problem with using active mode is that if the client computer is behind a firewall, the server probably won’t be able to connect to it. In that case, you can connect to the server using passive mode. With passive mode, Visual Studio establishes the connections for both the command port and the data port. To use passive mode, just select the Passive Mode option.

In some cases, an FTP server will require that you provide a username and password to connect to the server. Then, you’ll need to remove the check mark from the Anonymous Login option and enter the required information in the Username and Password text boxes that become available. Note that because this information is saved until you end Visual Studio, you only need to enter it the first time you connect to the server during a Visual Studio session.

After you enter the required information into the Choose Location dialog box, you click the Open button to return to the New Web Site dialog box. When you do, the location will look something like this:

  ftp://Murach/Ch03Cart

Then, you can just click the OK button to create the web site.

The dialog box for creating an FTP web site 
                                              


          Figure 4-3.  How to create an FTP web site

Description

  • To create a new FTP web site, select FTP from the Location drop-down list in the New Web Site dialog box. Then, click the Browse button to display the Choose Location dialog box shown above.
  • Enter the name of the server and the directory where you want to create the web site. You can typically leave the port set at 21.
  • Visual Studio can use either active mode or passive mode to establish connections to the FTP server. Active mode is the default. If the client is behind a firewall, though, you may need to use passive mode. To do that, select the Passive Mode option.
  • By default, Visual Studio logs you in to the FTP server as an anonymous user. However, some FTP servers require you to provide a username and password. In that case, you can deselect the Anonymous Login option and then enter your username and password. The username and password are saved until you end the Visual Studio session.
  • If you try to create a new FTP web site by entering a URL in the New Web Site dialog box, Visual Studio will display a dialog box that lets you specify whether you want to use passive mode and whether you want to log in as an anonymous user.
  • IIS can be configured to act as an FTP server as well as a web server. For more information, please see appendix A.

How to test an ASP.NET application



To test an ASP.NET application, you typically start by running it from within Visual Studio so that you can locate and correct any errors you encounter. This initial testing uses the default browser and, if you’re working with a file-system web site, the ASP.NET Development Server. Next, you test the application with other web browsers to make sure it works with them, and you test a file-system web site under IIS. Finally, you run the application from outside of Visual Studio to be sure it will work correctly in a production environment.

You’ll learn the techniques for performing all of these types of testing in the topics that follow. In addition, you’ll learn how to use the Exception Assistant dialog box that’s displayed if an error occurs while you’re testing an application.

How to test an application with the default browser

Unless you’ve changed it, Visual Studio uses Internet Explorer as its default browser. Figure 4-4 presents six different ways you can run a web application with the default browser. Three of these techniques start the debugger so you can use its features to debug any problems that might arise. The other three techniques do not start the debugger.

The first time you run a web application using one of the first three techniques, Visual Studio displays a dialog box indicating that debugging isn’t enabled in the web.config file. From this dialog box, you can choose to add a new web.config file with debugging enabled, or you can choose to run the application without debugging. In most cases, you’ll add a new web.config file with debugging enabled so that you can use the debugger with your application.

Before I go on, you should realize that before you can run an application with debugging on a remote server, a program called the Remote Debug Monitor must be installed and running on the server. For information on how to set up this program, see the help topic “How to: Set Up Remote Debugging.”

All of the techniques listed in this figure except the View in Browser command start the application and display the application’s designated start page. However, the View in Browser command displays the selected page. For example, if you right-click the Cart page and choose View in Browser, the Cart page will be displayed. This command is most appropriate for making sure that the pages of an application look the way you want them to.

At this point, you should realize that the type of web site you’re developing determines the web server that’s used to run the application. For example, if you’re developing a file-system web site, the ASP.NET Development Server is used to run the application. In that case, the URL for the page that’s displayed identifies the server as “localhost:” followed by a number that’s assigned by the development server. In contrast, if you’re developing an IIS web site, IIS is used to run the application. Then, the server is identified as just “localhost” for a local web site or by its actual name for a remote or FTP web site.

The Order page displayed in the default browser


Figure 4-4.  How to test an application with the default browser

Three ways to run an application with debugging

  1. Click the Start Debugging button in the Standard toolbar
  2. Press F5
  3. Choose the Debug->Start command

Three ways to run an application without debugging

  1. Press Ctrl+F5
  2. Choose Debug->Start Without Debugging
  3. Right-click a page in the Solution Explorer and choose View in Browser.

Three ways to stop an application that’s run with debugging

  1. Press Shift+F5
  2. Click the Stop Debugging button in the Debug toolbar
  3. Choose Debug->Stop Debugging

Description

  • If you run an application with debugging, you can use Visual Studio’s built-in debugger to find and correct program errors.
  • By default, an application is run using Internet Explorer. See figure 4-5 for information on using a different browser. To end the application, close the browser.

You should also realize that you can’t just run an FTP application from its FTP location. That’s because this location is used only to transfer files to and from the server. Instead, a browse location must be set up for the web site. A browse location is simply an IIS virtual directory that points to the directory that stores the files for the web site. Then, to access and run the web site, you enter the HTTP URL for the virtual directory. The first time you run an FTP web site, you will be asked to enter this URL. Because the URL is stored as part of the web site, you won’t need to enter it again.

How to test an application with a browser other than the default


 
Once you’ve thoroughly tested your application with Internet Explorer, you’ll want to test it with other browsers to make sure it works as expected. Figure 4-5 describes two ways to do that. First, you can right-click the starting page for the application in the Solution Explorer and choose the Browse With command. This displays a Browse With dialog box like the one shown in this figure. From this dialog box, you can choose the browser you want to use and then click the Browse button.

Notice that the list of browsers in the Browse With dialog box includes the Internal Web Browser. If you choose this browser, the page is displayed in a Browse window within Visual Studio. You can test the application from this browser just as you would from any other browser. Then, when you’re done with the browse operation, just close the Browse window.

You can also test an application with another browser by making that browser the default browser. To do that, right-click any page in the Solution Explorer and choose Browse With. Next, select the browser you want to designate as your default browser and click the Set As Default button. Then, click the Cancel button to close the Browse With dialog box. You can then use any of the techniques listed in figure 4-4 to start the application in the browser you selected. Note that setting a browser as the default is the only way to use the debugger with the browser. That’s because the Browse With command runs an application without debugging.

Sometimes, the browser you want to test an application with doesn’t appear in the Browse With dialog box even though it’s installed on your computer. In most cases, that’s because you installed the browser after installing Visual Studio. Then, you can add the browser by clicking the Add button in the Browse With dialog box to display the Add Program dialog box. This dialog box lets you locate the executable file for the browser you want to add and enter a “friendly” name that’s used for the browser in the Browse With dialog box.

The Browse With dialog box


Figure 4-5.  How to test an application with a browser other than the default

Two ways to test an application with a browser other than the default

  • Right-click the starting page for the application in the Solution Explorer and choose Browse With from the shortcut menu. In the Browse With dialog box that’s displayed, select the browser you want to use and click the Browse button.
  • Select the browser you want to use in the Browse With dialog box and then click the Set as Default button to make that browser the default. The next time you run the application, it will be displayed in the browser you selected.

Description

  • It’s important to test an ASP.NET application in any browsers that might be used to run the application.
  • If a browser isn’t included in the list of available browsers, you can add it to the list by clicking the Add button in the Browse With dialog box and then using the Add Program dialog box that’s displayed to add the desired browser.
  • If you select the Internal Web Browser option, the page is displayed in a Browse window within Visual Studio. To end the browse operation from this window, just close the window.
  • You’ll need to change the default browser if you want to use the debugger with another browser, since the Browse With command starts the application without debugging.

How to test a file-system web site with IIS


 
When you run a file-system web site, it runs under the ASP.NET Development Server by default. Because this server has limitations, however, you’ll want to be sure to test a file-system web site under IIS as well as under the development server. Figure 4-6 describes how you do that.

To start, you need to create a virtual directory for the web site as described in figure 4-1. Then, if you open the web site from this virtual directory, it will automatically run under IIS. Alternatively, you can open the file-system web site directly and change its start options so the URL you specify is used to start the application. In this figure, for example, you can see that the Use Custom Server option has been selected and the URL for the web site’s virtual directory has been entered in the Base URL text box.

This figure also lists the limitations of the ASP.NET Development Server. The most significant of these limitations is that it always runs under the current user’s security context, but your own user account probably has stronger security privileges than the account IIS runs ASP.NET applications under. As a result, when you move the application to a production web server, you may have to contend with security issues that weren’t apparent when you tested with the development server, especially if you access files or databases located in folders outside of the application’s folder structure.

The dialog box for specifying a web server


Figure 4-6.  How to test a file-system web site with IIS

How to test a file-system web site with IIS

  1. Create a virtual directory for the web site as described in figure 4-1.
  2. Open the web site from its virtual directory, or open the file-system web site and then use the Property Pages dialog box shown above to specify the URL for the virtual directory.
  3. Run the application using one of the techniques in figure 4-4.

Limitations of the ASP.NET Development Server

  • Can serve pages only to the local computer.
  • Runs in current user’s security context, so it doesn’t accurately test security issues.
  • Does not include an SMTP server, so it can’t be used to test email applications.
  • Uses a randomly chosen port rather than the standard HTTP port 80.

Description

  • By default, a file-system web site is run using the ASP.NET Development Server. To run a file-system web site using IIS, you can use one of the techniques above.
  • To open the Property Pages dialog box, right-click the project in the Solution Explorer and select Property Pages from the shortcut menu. Then, to change the server that’s used to run the web site, click the Start Options node, select the Use Custom Server option, and enter the URL of the virtual directory for the web site.

How to test an application from outside of Visual Studio

Once you’ve thoroughly tested and debugged an application from within Visual Studio, you’ll want to run it from outside of Visual Studio to make sure it works properly. Figure 4-7 describes how you do that.

To start, you open the browser you want to use. In this example, I used Mozilla Firefox. Then, you enter the URL for the starting page of the application and press Enter. When you do, a request for the page is sent to the server and the resulting page is displayed in the browser.

Note that to run a local IIS web site, you use “localhost” in the URL to identify the server. The URL in this figure, for example, refers to the Order.aspx page of the Ch03Cart web site. This web site is located in the ASPNET2005 directory of the local IIS server. In contrast, to run a remote IIS web site, you specify the actual server name in the URL like this: 

  http://mma1/ASPNET2005/Ch03Cart/ Order.aspx

And to run an FTP web site, you enter the browse location like this:

  http://Murach/Ch03Cart/Order.aspx

If you haven’t already tested an application from within Visual Studio in each browser that might be used to run the application, you should do that from outside Visual Studio. In addition, if the application retrieves and updates data in a database, you’ll want to test it simultaneously in two browser windows. To understand why, you need to realize that after an application retrieves data from a database, it closes the connection to the database. Because of that, two or more users can retrieve the same data at the same time. This is called concurrency, and it can cause concurrency errors when the data is updated.

In section 3 of this book, you’ll learn more about concurrency and how you avoid concurrency errors. For now, you should just realize that you’ll need to test your applications to be sure that they handle concurrency problems.

The Order page displayed in a Mozilla Firefox browser outside of Visual Studio


Figure 4-7.  How to test an application from outside of Visual Studio

Description

  1. You can run any IIS application from outside of Visual Studio. To do that, open the browser you want to use, enter the URL for the starting page of the application as shown above, and press Enter.
  2. When you run an application from outside of Visual Studio, you can run it in two or more browser windows simultaneously. That way, you can be sure that the application provides for any concurrency errors that can occur.
  3. If you want to use the debugger while testing for concurrency errors, you can run one instance of the application from within Visual Studio with debugging, and you can run another instance from outside of Visual Studio.
blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials