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?
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.
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.
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.
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.
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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With