OtoLeo
OtoLeo

Reputation: 363

Angular.js and IIS reload page

I am working on a web app using angular.js and a server-side component deployed on IIS express.
My problem is that pressing the reload button on the browser will display a 404 message, because obviously, the server does not recognize the URL (managed by angular).

On my app module I have the following:

angular.module('app').config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode($locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    }));
    $routeProvider.otherwise({ redirectTo: '/login' });
}]);  

Then, in each module I manage the routing for the corresponding pages, e.g.:

angular.module('login', [])

.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: 'src/app/login/login.tpl.html',
        controller: 'LoginCtrl',
        resolve: {
        }
    });
}])

My main page is /src/index.html

I have also tried adding the following rule in the web.config file, but it doesn't work either:

<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" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>  

Any thoughts? Thanks.

Update 1:
I forgot to mention that using the rule above shows the following error when reloading the page.

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

Upvotes: 1

Views: 625

Answers (1)

Norbert Huurnink
Norbert Huurnink

Reputation: 1316

You need to redirect to /src as that's where your index.html page is living. You get an error because it can't find an index/root page in your root directory, because there is none.

Upvotes: 0

Related Questions