Skip to content
  • iImagine
  • Register
  • Log In

Web Development School

Learning made easy.

  • Books
    • Beginning Web Development with ASP.Net Core & Client-Side Technologies
      • TOC
      • Part 1
        • Chapter 1: Static HTML – Designing the landing page
      • Part 2
        • Chapter 2: ASP.Net Core – Let’s talk Dynamic
        • Chapter 3: Introduction to ASP.Net Core MVC
          [ASP.Net Core v9]
      • Part 4
        • Chapter 7: Using Server Side & Client Side technologies together
          [ASP.Net Core v7 & Angular 15]
  • Environment Setup
    • Installing Angular
    • Installing Visual Studio 2022
    • Installing SQL Server 2022 Express
    • Installing Postman
    • Installing Git for Windows
  • Blog
  • iImagine WebSolutions
  • Events
  • Learning Videos
  • Toggle search form

Reuse for HTML: PART 2

In the last module, Reuse for HTML: PART 1, we began to make our header and footer reusable. But we lost them in the process and they stopped showing up on the car1-details.html webpage. We are going to fix that here in this module.

Note: The reason the includes are not working is for security reasons. The browser blocks these include statements based on JavaScript because by default it does not allow CORS (Cross-Origin Resource Sharing). So we need to set up and run our webpages from a server so the browser knows the included html files are from that same domain.

You can download the finished code for this module with the button below:

Download
Table Of Contents
  1. Setting up IIS (Internet Information Services)
    • Turn on IIS
    • Configure the website in IIS
      • Create the FredsCars Website
  2. Configure the Host file.
  3. Run the new website from IIS
  4. Update FredsCars.html with the header and footer components
    • Mapping Image Mime Types
  5. What's Next

Setting up IIS (Internet Information Services)

We are going to start by setting up a webhost server called IIS (Internet Information Services) on our local Windows environment and run our webpages through the host server instead of from our local file system so that the JavaScript to include the reusable html components will work.

NOTE: The instructions and screenshots in this module are written for Windows 11. But the procedures are very similar for the last few previous versions of Windows.

Turn on IIS

Start by Pressing Ctrl-Esc to access the start menu and search for Control Panel. Click the Control Panel result on the right to open it.

In the control panel, set the “View By” selection to “Large icons” and click the “Programs and Features” icon.

Next select, “Turn Windows features on or off”.

The Windows Features dialogue will pop up. Make sure the checkbox next to Internet Information Services is at least partially checked.

In the above screen shot a blank checkbox means none of the sub-features of the main feature are turned on. A checked checkbox with a blue fill means they are all turned on. And a dash with a blue fill means some of the sub-features are activated.

In the following screenshot you can see what I have selected on my local development machine. These are all the default selections so I didn’t have to change anything. Also very few features are selected because when we get into ASP.Net Core development in the following chapters you will see that Visual Studio comes with it’s own development server. Also most of the selections here are for the older version of ASP.Net from the .Net Full Framework rather then the newer ASP.Net Core framework.

Click the OK button. Once your computer finishes installing IIS you may need to reboot your computer.

Configure the website in IIS

Now that we have installed IIS it should show up in the start menu. In the start menu search for IIS and select the result icon.

IIS Manager will pop up as shown in the following screenshot.

Create the FredsCars Website

Once you’ve opened the Internet Information Services Manager, right click on Sites and select Add Website.

The Add Website dialogue will pop up. Enter the information into the dialogue the same as you see it in the screen shot below.

Make sure the values match for each setting in the Add Website dialogue.

Site name: FredsCars

Application pool: FredsCars

Physical path: C:\Development\FredsCars\HTML\Chapter01Mod10b (or the path where you’re development files are).

Binding Type: http

Binding Address: 127.0.0.1 (This is called the loopback address. Every computer has an IP Address and the loopback address loops back to your own computer for development.)

Port: 80 (This is the default port for the web and your browser.)

Host name: www.fredscars.com (This is the URL you are specifying should be typed in the browser to find this website.)

Click OK and you will see the FredsCars website appear under Sites.

Expand the FredsCars site and you’ll see the current html files and the css, include, and resource folders we are currently working with.

Configure the Host file.

Right now if you type the www.fredscars.com URL into your browser it will not be able to find the website and you will get a 404 Page Not Found error. We have to tell your local development computer that the site at www.fredscars.com can be found on the same local computer at the loopback address of 127.0.0.1

Note: Every computer and every web server has an IP address. When you type in www.amazon.com or www.microsoft.com, the request is sent out to the internet and routed to a DNS server that can look at the address you typed in the browser and translate it to an IP Address. For example www.amazon.com might become 108.174.10.10. So www.amazon.com/orders is the same as 108.174.10.10/orders.


In order to fix the 404 error we need to add an entry to the local computer’s host file.

Open up TextPad, NotePad, or your favorite text editor in Administrator mode.

In the screenshot below, I search for TextPad in the Start Menu, right click on the resulting TextPad app, and select Run as administrator.

Your system will ask you the following: “Do you want to allow this application to make changes to your device?” Click yes and TextPad will open in Administrator mode.

Click File -> Open and navigate to “C:\Windows\System32\drivers\etc” so you can open the host file.

Enter the following entry in the host file:

127.0.0.1 www.fredscars.com

The following screenshot is what my host file looks like after I make the fredscars entry.

There are a lot of comment lines in the host file starting with the ‘#’ character describing what the file does and how to add an entry. My file has some IP Mappings that were automatically inserted when I installed Docker. Docker is a tool to run applications in their own container and is used heavily in ASP.Net Core deployment but will probably be outside the scope of this book.

Don’t forget to save the file before closing it.

Run the new website from IIS

Type www.fredscars.com/car1-details.html into the address bar of your browser and the header and footer should now reappear in the browser and are being generated by the w3-include-html attribute we learned about in module 10a using the header.html and footer.html include files we created.

Update FredsCars.html with the header and footer components

Now we need to go back to FredsCars.html and make the same edits we did for car1-details.html in order to use the header and footer html components and ensure if we ever make a change to the header and footer we only need to make it in one place and that change will trickle through the entire site.

Modify the contents of fredscars.html with the following code, save your file, and type www.fredscars.com/fredscars.html in the address bar of your browser.

<!doctype html>
<html>
<head>
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <title>Freds Cars, Trucks & Jeeps</title>
   <script src="https://www.w3schools.com/lib/w3.js"></script>

   <!-- Bootstrap CSS -->
   <!-- CSS only: not combined with popper -->
   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
         rel="stylesheet"
	 integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
	crossorigin="anonymous">

   <link rel="stylesheet" href="css/site.css">
   <!-- ... -->
   <!-- Styles (Leave as is) -->
   <!-- ... -->

   <!-- ... -->
   <!-- Scripts (Leave as is) -->
   <!-- ... -->
</head>
<body>
   <div w3-include-html="include/header.html"></div>

   <div class="container-fluid my-4 text-center">
      <h1>Welcome to Fred's Cars!</h1>
      Where you'll always find the right car, truck, or jeep.
      Thank you for visiting our site.

      <div class="container-fluid mx-0 row"
           style="margin-top: 20px;">
         <!-- Categories Section (Leave as is) -->
   
         <!-- Results Section (Leave as is -->
      </div>
   </div>
   <div class="spacer"></div>

   <div w3-include-html="include/footer.html"></div>

   <script>
      w3.includeHTML();
   </script>
</body>
</html>

Mapping Image Mime Types

At this point you may run into one more challenge. In the screenshot below, we are now running the landing page through IIS. And the header and footer are now being generated from the reusable html files. But some of the images are not showing up. IIS is not serving images with a .webp extension.

The images that are showing up have a .png file extension which IIS allows by default. The images that are not showing up have a .webp file extension which IIS does not serve by default. To fix this we can add a MIME Type in the FredsCars IIS site.

In IIS Manager, double click MimeTypes for the FredsCars site.

Click Add in the upper right corner of the MIME Types feature screen to add the .webp MIME Type and then click OK.

Refresh your browser and you should see a complete working version of the landing page using the reusable header and footer and all images should be rendering from IIS.

What’s Next

Now that we have figured out how to make the same header and footer reusable across the site, in the next part of the module let’s turn our attention back to the details page and finish it up.

< Prev
Next >

Leave a ReplyCancel reply

Chapter 1: Static HTML – Designing the landing page.

  • Static HTML – Designing the landing page.
  • Let’s get started!
  • Mock your site with HTML
  • Make CSS easy with Bootstrap
  • Mock your content
  • Introducing JavaScript
  • JavaScript Code Improvements
  • Results Data
  • Images and the HTML Image Element.
  • Revisiting Reusability for CSS and JavaScript
  • Reuse for HTML: PART 1
  • Reuse for HTML: PART 2
  • Details Page – Using a Bootstrap Component
  • Creating Links
  • Chapter One Conclusion

Chapter 2: ASP.Net Core – Let’s talk Dynamic

  • Introduction to ASP.Net Core
  • What is .Net?
  • What is ASP.Net
  • Introduction to Entity Framework Core

Chapter 3: ASP.Net MVC Core – Models, Views, and Controllers [ASP.Net Core v9]

  • Introduction to ASP.Net Core MVC
  • Create the project: ASP.Net Core MVC
  • Explore the ASP.Net Core Empty Web Project Template
  • Configure the Application for MVC
  • Create a Controller: Home Controller
  • Create a View: Index View for the Home Controller
  • Install Bootstrap using Libman
  • Create the Layout template
  • Create the Model
  • Install EF Core & Create the Database
  • Seed the Database: Loading test data
  • DI (Dependency Injection): Display a List of Vehicles
  • Repository Pattern: The Vehicles Repo
  • Unit Test 1: Home Controller Can Use Vehicle Repository
  • Unit Test 2: Vehicle Repository Can Return List
  • Add the ImagePath Migration and Thumbnail images to results
  • Pagination: Create a Custom Tag Helper
  • Sorting
  • Category Filter
  • Partial View: Break out the vehicle results
  • View Component: Create dynamic category buttons
  • Create the Details page
  • Create the Create Page

Chapter 7: Using Server Side & Client Side technologies together. [ASP.Net Core v7 & Angular v15]

  • Intro to Full Stack Development
  • Fred’s Cars – Full Stack Development
  • Prepare the environment
  • Create the Visual Studio Solution
  • Add the ASP.Net Core Web API project
  • Add the Angular Project
  • Wire it up!
  • WeatherForecast: Understanding the basics
  • Vehicles API Controller: Mock Data
  • Vehicles Angular Component: Consuming Data
  • Routing and Navigation
  • Using a Component Library: Angular Material
  • Our first Angular Material Component: MatToolbar
  • Configuring for Saas: CSS with superpowers
  • Create the Header & Footer components
  • Displaying Results with MatTable
  • Loading: Using a Progress Spinner
  • MatTable: Client-Side Paging and Sorting
  • MatSidenav: Create a Search Sidebar
  • MatCheckbox: Category Search UI
  • Adding an image to the welcome page
  • Create the database with Entity Framework Core migrations
  • MatPaginator & PageEvent: Custom Server-Side Paging
  • Unit Testing: Custom Server-Side Paging
  • Repository Pattern: VehicleRepository
  • Unit Test: Paging in the Vehicles controller
  • Server-Side Sorting
  • Unit Tests: Sorting
  • Filter (Quick Search)
  • Unit Tests: Filter feature
  • Advanced Search: Categories
  • Unit Tests: Search by category
  • Progress Spinner: Final Fix

TOC

  • What were WebForms?
  • Enter MVC
    • Understanding MVC
    • Advantages of MVC
  • ASP.Net Core MVC – A total rewrite
  • ASP.Net Core 2 MVC – Here come Razor Pages
    • Understanding Razor Pages
  • ASP.Net Core 3 – Dropping the MVC reference
    • Understanding Blazor
  • Dropping the MVC reference
  • Hello .Net 5!
  • What’s Next? – Here comes .Net 6.

Recent Posts

  • Angular Commands Cheat Sheet
  • Installing Git for Windows
  • Installing Postman
  • Installing SQL Server 2022 Express
  • Installing Visual Studio 2022

Recent Comments

No comments to show.

Archives

  • November 2023
  • October 2023
  • June 2023
  • October 2021

Categories

  • Angular
  • ASP.Net
  • Environment Setup
  • See All
  • SQL Server
  • Visual Studio
  • Web API & Rest Services

WordPress Theme Editor

Copyright © 2025 Web Development School.

Powered by PressBook Blog WordPress theme