Introducing ASP.NET—Using localhost
By putting your files within
C:\Inetpub\wwwroot, you give your web server access to them. If you’ve been developing web pages for a long time, habit may drive you to open files directly in your browser by double-clicking on the HTML files. However, because ASP.NET is a server-side language, your web server needs to have a crack at the file before it’s sent to your browser for display. If the server doesn’t get this opportunity, the ASP.NET code won’t be converted into HTML that your browser can understand. For this reason, ASP.NET files can’t be opened directly from the disk using Windows Explorer.
Your local web server can be accessed through a special web address that indicates the current computer:
http://localhost/. If you try this now, IIS will open up a default help page (although this behavior will vary depending on the settings of your Windows installation; for example, if you get an error instead of the default help page, don’t worry).
What you need to keep in mind, though, is that the address you’ll use to access local web applications will always start with
http://localhost/, and that, by default, this root address points to the folder on your disk.
To see this in practice, create a new file named index.htm inside
C:\Inetpub\wwwroot, with the following contents:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Simple HTML Page</title> </head> <body> <P>This is a simple HTML page. </body> </html>
Now, load this page through
http://localhost/index.htm, as shown in Figure 1.6, "Testing IIS".
- Experiencing an Error?
- If the page doesn’t load as illustrated in Figure 1.6, "Testing IIS", your IIS installation has problems. You might want to double-check that you correctly followed the steps for installing it, and re-check the IIS configuration procedure.
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.