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

Configuring the Web Server

This localhost name is equivalent to the so-called loopback IP address, 127.0.0.1, so you can get the same results by entering http://127.0.0.1/index.htm into your browser. If you know them, you can also use the name or IP address of your machine to the same end.

Note that if you do try any of these equivalents, a dialog will appear before the page is opened, to ask you for your network credentials. This occurs because you’re no longer using your local authentication, which is implicit with localhost.

Stopping and Starting IIS

Now that we have IIS up and running, and ASP.NET installed, let’s look at how you can start, stop, and restart IIS if the need arises. For the most part, you’ll always want to have IIS running; however, if you want to shut it down temporarily for any reason (such as security concerns), you can. Also, some external programs may stop IIS upon launch because of potential security vulnerabilities, so you’ll need to start it again yourself. If you want to stop IIS when it’s not being used, simply open the Internet Information Services management console, right-click on Default Web Site and select Stop. Alternatively, after selecting Default Web Site, you can use the Stop, Pause, and Play icons from the toolbar.

Virtual Directories

As we saw in the section called “Where do I Put my Files?”, physical sub-folders of C:\Inetpub\wwwroot also become subdirectories of the web site. For instance, imagine your company has a web server that serves documents from C:\Inetpub\wwwroot. Your users can access these documents through http://www.example.com/. If you create a subfolder of wwwroot, named about, files in that directory can be accessed via http://www.example.com/about/.

You could also set up another subdirectory in your web site, but serve files from a different location on the disk. If, for instance, you were developing another web application, you could store the files for it in C:\dev\OrderSystem. You could then create within IIS a new virtual directory called, say, order, which mapped to this location. This new site would then be accessible through the URL http://www.example.com/order/. As this application is in development, you would probably want to set IIS to hide this virtual directory from the public until the project is complete; your existing web site would still be visible.

By default, a virtual directory, called IISHelp, is preconfigured in IIS; it maps to c:\windows\help\iishelp. You can see in Figure 1.7 that IISHelp contains

15

Chapter 1: Introducing ASP.NET and the .NET Platform

subdirectories called common and iis—these are physical folders inside c:\windows\help\iishelp.

Figure 1.7. The IISHelp virtual directory

Let’s create a virtual directory on your server, and test it with a simple page:

1.First, you need to create on your disk a folder to which your virtual directory will be mapped. Create a folder called WebDocs in an easily accessible location on your disk, such as C:\, and create a folder named Learning inside that folder. We’ll use this folder, C:\WebDocs\Learning, for various exercises in this book.

2.Copy the index.htm file you created earlier into your newly created Learning folder.

3.In the Internet Information Services management console, right-click Default Web Site and select New > Virtual Directory. The Virtual Directory Creation Wizard will appear. Click Next.

4.You need to choose an alias for your virtual directory: enter Learning, then click Next.

5.Browse and select the Learning folder you created at step 1, or enter its full path (C:\WebDocs\Learning). Click Next.

16

Configuring the Web Server

6.In the next screen, you can select permissions settings for your directory. Typically, you’ll want to leave the default options (Read and Run scripts) checked. Click Next.

7.Click Finish. You’ll see your new virtual directory as a child of Default Web Site, as Figure 1.8 illustrates.

Figure 1.8. Creating a new virtual directory

8.Load this link by entering http://localhost/Learning/index.htm into the address bar of your browser. If everything went well, you should see your little HTML page load, as has the one in Figure 1.9.

Figure 1.9. Testing your new virtual directory

Note that by loading the page through the HTTP protocol, your request goes through IIS. Since index.htm is a simple HTML page that doesn’t need any server-side processing, you can also load it directly from the disk. However, this

17

Chapter 1: Introducing ASP.NET and the .NET Platform

won’t be the case with the ASP.NET scripts you’ll see through the rest of this book.

Once your new virtual directory has been created, you can see and configure it through the Internet Information Services management console shown in Figure 1.8. You can see the folder’s contents in the right-hand panel.

As index.htm is one of the default document names, you can access that page just by entering http://localhost/Learning/ into your browser’s address bar. To see and edit the default document names for a virtual directory (or any directory, for that matter), you can right-click the directory’s name in the IIS management console, click Properties, and select the Documents tab. You’ll see the dialog displayed in Figure 1.10.

Figure 1.10. Default document types for the Learning virtual directory

By default, when we request a directory without specifying a filename, IIS looks for a page with the name of one of the default documents, such as index.htm or default.htm. If there is no index page, IIS assumes we want to see the contents of the requested location. This operation is allowed only if the Directory Browsing

18

Configuring the Web Server

option is selected for the directory in question. You’ll find that option in the

Directory tab of the Properties window.

Directory Browsing

Enabling directory browsing is not something you’d usually want to do. Allowing visitors to freely see and access all the files and directories that make up your web page is not only a little messy and unprofessional, but also increases the potential for security issues (you don’t want any hackers to stick their nose into your code, do you?). So, by default, IIS won’t allow directory browsing when a directory is requested: if a default file such as index.htm isn’t there, ready to be served to the visitor, a message reading “Directory Listing Denied” will be served instead.

To change your virtual directory’s options, you have to right-click the virtual directory (Learning, in our case) in the IIS console, and choose Properties. The

Properties dialog that we’ve just used lets us configure various useful properties, including:

Virtual Directory

This option allows you to configure directory-level

 

properties, including path information, the virtual

 

directory name, access permissions, etc. Everything

 

that was set up through the wizard is modifiable

 

through this tab.

Documents

This option allows you to configure a default page that

 

displays when the user types in a full URL. For in-

 

stance, because default.aspx is listed as a default

 

page, the user need only enter http://www.mys-

 

ite.com/, rather than http://www.mysite.com/de-

 

fault.aspx, into the browser’s address bar. You can

 

easily change and remove these default pages by select-

 

ing the appropriate button to the right of the menu.

Directory Security

This option provides you with security configuration

 

settings for the virtual directory.

HTTP Headers

This option gives you the ability to forcefully control

 

page caching on the server, add custom HTTP Headers,

 

Edit Ratings (this helps identify the content your site

 

provides to users), and create MIME types. Don’t

 

worry about this for now.

19