Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular and IIS WebApplication (or virtual directory)

We have webserver with an IIS website and an IIS Web Application underneath. The web application's root is: http://website/webapplication/. When deployed I get the following error in the browser:

http://website/app/app.component.html 404 (Not Found)

app/app.component.html 404 (Not Found)

My component:

@Component({
    selector: "app",
    templateUrl: "./app/app.component.html"
})

The file app.component.html does indeed not exist under /app/app.component.html, but it does exist at: /webapplication/app/app.component.html.

So, my conclusion is that Angular only works when in the root of a website. In the html header I have set the tag to: <base href="/webapplication/">, but that doesn't help.

It seems like a normal setup, I can't believe the template resolving in Angular fails, I must be missing something... Does anyone know a solution to this?

like image 372
Mcanic Avatar asked Jul 25 '16 10:07

Mcanic


People also ask

What is the difference between virtual directory and application in IIS?

Virtual directories and applications are now separate objects, and they exist in a hierarchical relationship in the IIS configuration schema. Briefly, a site contains one or more applications, an application contains one or more virtual directories, and a virtual directory maps to a physical directory on a computer.

Can angular project be deployed to IIS?

Use the Angular Tour of Heroes as a sample Angular Router application. Install IIS with the URL Rewrite Module. Deploy Tour of Heroes to the web root in IIS. Deploy Tour of Heroes to a specific sub-folder in IIS using the base-href flag.

What is the use of virtual directory in IIS?

A virtual directory is a directory name (also referred to as path) that you specify in Internet Information Services (IIS) 7 and map to a physical directory on a local or remote server.

How do I convert virtual directory to application in IIS?

In IIS Manager, expand the node for the local computer and then expand the Sites folder. Right-click the folder that you want to convert to an application and then click Convert to Application. The Add Application dialog box is displayed. Click OK.


Video Answer


1 Answers

I couldn't use most of the suggestions on the web regarding fixing this issue, I have no idea why. I played around with settings util I got it working. Here is what I used:

  • IIS 10.0
  • Angular 6.1.0 project
  • Virtual Directory converted to application
  • App Pool: No Managed Code

webconfig:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="true" />
    <rewrite>
      <rules>
        <rule name="AngularJS Routes" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
       <action type="Rewrite" url="/myapp/index.html" />
      </rule>
    </rules>
    </rewrite>
  </system.webServer>
</configuration>

my root index.html file:

<base href="./">   <---- make sure you have the dot in there!
like image 170
Post Impatica Avatar answered Oct 03 '22 09:10

Post Impatica