Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

asp.net mvc - AngularJS routing not working after site hosted into IIS

We are creating SPA technique using AngularJS in ASP.NET MVC framework,AngularJS routing between pages are working fine when it's run from VS2013,but after hosting the application in to IIS7.5 routing not working,

Routing Script:

   var appRoot = angular.module('main', ['ngRoute', 'ngGrid', 'ngResource']);     //Define the main module

    appRoot
        .config(['$routeProvider', function ($routeProvider) {
            //Setup routes to load partial templates from server. TemplateUrl is the location for the server view (Razor .cshtml view)
            $routeProvider
                .when('/home', { templateUrl: '/home/main', controller: 'HomeController' }) .otherwise({ redirectTo: '/home' });
        }])
        .controller('RootController', ['$scope', '$route', '$routeParams', '$location', function ($scope, $route, $routeParams, $location) {
            $scope.$on('$routeChangeSuccess', function (e, current, previous) {
                $scope.activeViewPath = $location.path();
            });
        }]);

Index.html:

 <li class="mt" data-ng-class="{active : activeViewPath==='/home'}">
                    <a href='#/home'>
                        <i class="fa fa-dashboard"></i>
                        <span>Dashboard Home</span>
                    </a>
                </li>


  <div class="col-lg-9 main-chart" ng-view="">
                </div>

Project Structure:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

do you get any JS error when you run it on IIS?

are you using bundles? If so check if the problem happens because of minification/bundle creation adding BundleTable.EnableOptimizations = true; in RegisterBundles method and trying again in VS.

Otherwise I suggest you to run on local IIS (right click on project, tab "Web",section "Servers") and see if it works correctly.

Depending of your routing you should <base href="@Url.Content("~/")" /> in template head and get rid of "#" from url using $locationProvider.html5Mode(true); on route configuration.

If none of the above are useful please add more details to your request.

Have a nice day,

Alberto


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...