Running a Simple Web Application with IIS 10.0

45965 VIEWS

·

Internet Information Services, commonly abbreviated to IIS, is Microsoft’s web server for use on Windows machines. The most recent version, IIS 10.0, comes shipped with Windows Server 2016 and Windows 10. Due to this, it’s easy to see why IIS 10.0 may be a viable web server option when developing a web application. Below I will show how to run your locally developed web application using IIS 10.0 for Windows.

Enabling IIS 10.0 on your Windows 10 machine

In order to run our web application locally using IIS, we first need to enable IIS 10.0 on our machine. For the sake of this example, let’s cover the case of enabling IIS 10.0 on a Windows 10 machine. The first step in this process is to navigate to the Control Panel → Programs → Programs and Features. Click on the link labeled “Turn Windows features on or off.” This will open the Windows Features dialog where you can find and enable Internet Information Services.

After making the selections shown in the above images, click “OK.” Doing so will prompt Windows to make the proposed changes, and IIS 10.0 will be enabled on your machine. This is the very first step in utilizing IIS 10.0 for local development purposes.

Setting up and running your site

After completing the steps listed above, a new directory on your C drive will be created. This will be located at C:\inetpub. The directory will have the folders shown in the image below:

Right now, we are interested in the wwwroot directory. This will contain two files: iisstart.htm and iistart.png. Here, I will create a third—a simple html file called: helloworld.html. This file will contain the following html:

 
Hello World Page
Hello world!

The next step is to open the console for setting up and managing your IIS websites (this is called the Internet Information Services (IIS) Manager). When we enabled IIS 10.0 on our machine, it set up a default website for us. However, we will remove this instance and set one up on our own. Our IIS Manager, without any sites set up for our server, will appear as follows:

In the upper right-hand corner of the IIS Manager, click “Add Website.” Here we will set up a test website that leverages the C:\inetpub\wwwroot directory we added the helloworld.html file to earlier. We can add the site with the name “Test Site” and set the physical path of our site content to C:\inetpub\wwwroot. Without altering any other fields, leave the “Start Website Immediately” checkbox checked and click “OK.” This will create the site in IIS and start the site so we can visit it immediately in a browser.

To see our “Hello World” page we configured earlier, open a web browser and visit the following URL: http://localhost/helloworld.html

As you can see, this allows us to view our web page as designed. It is also important to note that we can both stop and start our web application from the IIS Manager. With the site highlighted in the console, there is a “Manage Website” section on the right-hand side of the console with options to Restart, Start and Stop. Clicking “Stop” will stop our site from running on our server while “Start” will spin it up again.

A few important tools and settings…

Developing within IIS gives us some useful options for customizing our development experience. One of the most important ones, in my opinion, is the use of virtual directories. It’s possible that you may want to utilize resources that reside in a different directory than C:\inetpub\wwwroot. This may be a way to add the ability to use images in your application that exist elsewhere on your machine. Virtual directories can help with this.

First, let’s add an image that lives elsewhere on our PC to our “Hello World” Page. Our attempt will be to add an image with the filename hi.png (located in C:\images) to our “Hello World” Page. I have altered the HTML of helloworld.html to read as follows:

 
Hello World Page
Hello world!

When we attempt to visit this page, the image will not load. We will need to add this as a virtual directory to add images to our web application running on IIS. The first step is to right-click on “Test Site” in our IIS Manager and select the option to “Add Virtual Directory.” The options are quite simple from here, as you only need to provide an alias for the directory and the physical path. For these options I will set “images” as the alias, and the physical path will obviously be C:\images, as noted earlier.

Before adding the virtual directory:

After adding the virtual directory:

Logging settings for IIS are also configurable from within IIS Manager. Simply by highlighting the site name in our IIS Manager, we can view a list of icons depicting our configurable settings for our site. Logging is one of those icons:

After double-clicking on Logging, we are brought to a configuration page with settings that will dictate how our IIS web server will log requests. The settings that will often be dealt with the most on this screen are the location for saving the log files and the log file format you wish to record the requests with.

By checking or setting the directory to which you wish to log to, it will be easy to locate and view your logs when you need to debug your application. As for format, you can select from several options such as IIS, NCSA, W3C, or a custom log format. Please see the image below to view the screen provided by IIS Manager for configuring logging settings.

Conclusion

IIS 10.0 is just one of the many web server options for quickly setting up and running a web application on your machine. If you’re running Windows 10 on your computer, it may be the easiest way to get started, as it is included with your operating system. Once you understand the steps behind enabling IIS 10.0 on your PC and setting up a simple website, you can quickly get into the development of the application itself.


Scott Fitzpatrick has over 5 years of experience as a software developer. He has worked with many languages, including Java, ColdFusion, HTML/CSS, JavaScript and SQL. Scott is a regular contributor at Fixate IO.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Menu
Skip to toolbar