Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Build Your Own ASP.NET 2.0 Web Site Using CSharp And VB (2006) [eng].pdf
Скачиваний:
77
Добавлен:
16.08.2013
Размер:
15.69 Mб
Скачать

Chapter 5: Building Web Applications

Developer will stop the application automatically. Otherwise, you’d need to stop it manually by selecting Debug > Stop Debugging, or clicking the Stop button shown in Figure 5.18.

Figure 5.18. Stopping debug mode

To change the browser that’s used to execute your web applications, first make sure that none of your projects are running. Then, right-click the root node in

Solution Explorer, and select Browse With to display the dialog shown in Figure 5.19. Select Internet Explorer, click Set as Default, and click Browse.

Figure 5.19. Setting the default browser in Visual Web Developer

Using IIS

You can continue your journey through this book using Visual Web Developer’s integrated web server, or you can make use of IIS. Although Microsoft recommends that we stick with Visual Web Developer for learning purposes, it’s very easy to use IIS. Even if you develop your application using the integrated web server, it’s beneficial to test your application using IIS as well, because when it’s shipped to production, your application will end up running on an IIS server anyway.

To run your web application using IIS, you’ll need to create an IIS virtual directory and make it point to the project’s physical folder on the disk. We’ll create a vir-

160

Using IIS

tual directory named Dorknozzle, so the URL of your web application will be http://localhost/Dorknozzle.

Start by opening the Internet Services Manager by selecting Start > All Programs

> Administrative Tools > Internet Information Services. In the tree in the left-hand pane, right-click the Default Web Site node, and choose New > Virtual Directory from the context menu, as shown in Figure 5.20.

Figure 5.20. Creating a new virtual directory

The Virtual Directory Creation Wizard will appear and, in its second screen, will ask you to specify an alias for your virtual directory. Choose Dorknozzle. The next screen will ask you for the path to this virtual folder—choose C:\WebDocs\Dorknozzle (or the folder you’ve used). Leave all the other settings to their defaults. After the wizard closes, you’ll be able to see your new virtual folder as a child of the Default Web Site node.

Let’s spend some time learning about your new virtual directory. Right-click the

Dorknozzle node in the Internet Services Manager, and choose Properties. A dialog like the one shown in Figure 5.21 will open, allowing you to configure the virtual directory’s properties.

161

Chapter 5: Building Web Applications

Figure 5.21. Editing the virtual directory’s properties

The Virtual Directory tab shows the basic settings of your virtual directory. If you look below the Application Settings header, you can see that the virtual directory has been configured as an IIS Application. When a virtual directory is set as an IIS application, IIS takes special care of that location by isolating all of that directory’s pages and subdirectories into what’s called an application domain. This approach offers numerous benefits:

code isolation

Code that executes within one application can't access code in other applications. So even if we built an intranet web application for a company’s staff, then placed a separate application for external users on the same web server, code would never cross-reference or conflict between those two applications.

application stabilization

Each application is isolated from all others, so if one application crashes or stops running, it has no effect on other applications that might be running on the same web server.

162

Using IIS

application level security policies

You can set different permissions for the different applications on the server. What this means is that the credentials that are used to log into one application can be totally different from those used to access a second application on the same server. We’ll discuss this in detail in Chapter 13.

settings configuration on a per-application basis

You can affect numerous other configuration settings for each application through Internet Services Manager, or Global.asax and Web.config, which are two special files located in the root directory of the application.

The Global.asax file handles application-wide events and sets applicationwide directives, while the Web.config file specifies configuration settings for the application. In addition to these two special files, every ASP.NET web application can contain a number of special folders, such as App_Themes, App_Code or App_Data. We’ll talk more about these details a little later in this chapter.

Applications and Visual Web Developer’s Web Server

When you use Visual Web Developer’s integrated web server to run your project, the virtual directory it creates for you on the spot is also set as an application, so it, too, enjoys all the benefits mentioned above.

Select the Virtual Directory tab in the Dorknozzle Properties dialog. If you click the Remove button that appears next to the application name, be aware that the action won’t remove the virtual directory itself: it will remove that application’s IIS application properties. When you click Remove, the button will be replaced by a

Create button, which will reinstate the directory as an IIS application.

163

Chapter 5: Building Web Applications

Figure 5.22. Adding a default name for the document

While you’re here, it’s a good idea to check that Default.aspx is included as a default file. If it is, then requesting http://localhost/Dorknozzle will load http://localhost/Dorknozzle/Default.aspx by default. To check this, click the Documents tab. If Default.aspx isn’t in the list, add it by clicking the Add… button and entering the filename, as shown in Figure 5.22.

Finally, click OK to close the Dorknozzle Properties window.

If no default document exists in the Dorknozzle folder, the web server will attempt to return a list of the files and folders inside the Dorknozzle folder—an operation that will only succeed if the Directory Browsing option shown in Figure 5.21 is enabled. If this option is left in its default, disabled state, this operation will result in an error.

Now, if you load http://localhost/Dorknozzle/ using any web browser, you should see a little magic (as Figure 5.23 reveals)!

164