Tips for Running an Angular app in IIS

Laurie Atkinson, Premier Developer Senior Consultant, A few tweaks are necessary to take an Angular app and move it to IIS. Here is a list of changes required to get everything running smoothly.

Using the Angular-CLI to generate an Angular SPA is an excellent way to scaffold out a well-organized application. This tool also includes a production build step that should allow you to xcopy your application to the web server of your choice. We’ll start here and discuss the necessary modifications to successfully run your application in IIS.

Use the Angular-CLI to create a production package

First decide whether the application will be located at the root in IIS (e.g. http://server-name) or in a path below the root (e.g. http://server-name/my-app).

If deploying to the root, run the Angular CLI build command:


If deploying to a path beneath the root, run the Angular CLI build command with the base-href option set to the name of application directory.


The base-href option modifies the base element in the index.html, so it looks as follows. This is required for routing to work correctly.


Create an IIS web application

Add the web site, or application, or virtual directory to IIS and set the physical path to the location of the dist folder created by the Angular CLI.


Any one of these three options shown below will work.


Install the URL Rewrite Module into IIS

This next step is required to support deep-linking, which is the capability for the user to navigate directly to a page by typing the route into the address bar instead of using the Angular routing. Deep-linking causes a problem for IIS because the URL that the user attempts to access is not known to the server and therefore the user receives a 404 response. The solution is for the server to always return the root of the application, even if the user requests a path within the application.

Get the URL Rewrite Module installer here:

After installing you should see a new icon in the IIS Manager.


Add web.config file with a URL Rewrite rule

All requests to this web application that are not for files or folders should be directed to the root of the application. For an application or virtual directory under the default web site, the URL should be set to the alias, (e.g. “/MyApp/”). For a web site at the root of the server, the URL should be set to “/”.

      <rule name="Angular Routes" stopProcessing="true">
        <match url=".*" />
	  <conditions logicalGrouping="MatchAll">
	    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
	    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
	  <action type="Rewrite" url="/MyApp/" />
	  <!--<action type="Rewrite" url="/" />-->


Problem: Navigating directly to a route results in a 404.

Solution: Make sure the web.config is correct and the URL property in the web.config matches both the base href in the index.html and the web application or virtual directory alias if necessary.

Problem: Navigating directly to a route results in a 500 or an error message related to the web.config.

Solution: Install the URL Rewrite module.

Problem: Navigating directly to a route displays a broken page and network/console errors show 404 results for js and css requests.

Solution: Verify that the base href in the index.html exactly matches the URL in the rewrite rule and that the slashes surrounding the name are not missing.

Comments (3)

  1. Praveen says:

    I create a Angular application using Microsoft.AspnetCore.SpaTemplates template with below commands:

    dotnet new –install Microsoft.AspnetCore.SpaTemplates::

    dotnet new angular

    Everything works fine when I debug from Visual Studio 2017.

    The same application when published to IIS virtual directory does not work (it does not take the virtual directory name). I installed .NET Core Windows Server Hosting Bundle and the application pool is set to use .NET CLR version as “No Managed Code”.

    when I run “ng build”, it says “compiler-cli” is not installed properly. Any idea how to get this working?

    1. Praveen,
      I have not used Microsoft.AspnetCore.SpaTemplates, but I don’t see that it uses the Angular CLI. So, none of the ng commands would apply in this case. You would need to manually change the index.html file to

      This page contains a section “Publishing for deployment” that you could take a look at for other issues:

      1. The blog removed my attempt to include html. You need to manually change the index.html file to
        base href=”/your-virtual-directory/”

Skip to main content