Josef Josef - 1 year ago 191
AngularJS Question mvc hosting angular app with html5mode and routing

Alright, so I am hosting an angularjs inside mvc 5 and are using the

in my angular app to get rid of all hash signs in the url.
Everything works great, however, with my current setup that looks like this:


name: "Default",
url: "app/{angular}",
defaults: new { controller = "Ng", action = "Index", angular= UrlParameter.Optional }

So that when I navigate to
my Ng/Index action returns the view which contains the ng-view container and the angular app is now active and working with the route provided

Now, my problem here is, when I navigate to
it returns a dir listning not allowed error which I cannot understand. Shouldn't my index action be returned as the angular parameter is set to optional?

And can I somehow avoid the "app" completely and still get my angular app to work? I have tried some rewrite rules but that gives me alot of errors because I am making use of the mvc bundling and minification functionality.

I could live with the url being the format it currently is but without the need to provide the optional parameter, like

Also, it's only an angular app, no other mvc view than the index.cshtml wrapper.

This guy seems to get it to work, but I can't see his mvc routes

Answer Source

Try adding this in your web.config sytem.webserver settings.

    <modules runAllManagedModulesForAllRequests="true"/>


Try changing your RouteConfig.cs, like this:

        name: "Default",
        url: "app/{*.}",
        defaults: new { controller = "Ng", action = "Index" }


I had completely forgoten about this question, but now I just realized that maybe the problem is that you haven't configured your IIS Server to work with Html5Mode, have a look at this:

Concretelly this part:

Azure IIS Rewrites:

      <rule name="Main Rule" 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="/" />

I hope that this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download