asp.net-mvc – 在将站点托管到IIS之后,AngularJS路由无法正常工作

我们在ASP.NET MVC框架中使用AngularJS创建SPA技术,从VS2013运行时,页面间的AngularJS路由工作正常,但是在将应用程序托管到IIS7.5路由不起作用之后,

路由脚本:

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>

项目结构:

解决方法

在IIS上运行它时会出现任何JS错误吗?

你在使用捆绑包吗?如果是,请检查是否因为缩小/捆绑创建添加而发生问题
BundleTable.EnableOptimizations = true;
在RegisterBundles方法中再次尝试在VS.

否则,我建议您在本地IIS上运行(右键单击项目,选项卡“Web”,“服务器”部分),看看它是否正常工作.

根据您的路由,您应该< base href =“@ Url.Content(”〜/“)”/>在模板头部并使用$locationProvider.html5Mode(true)从网址中删除“#”;在路线配置.

如果以上都不是有用的,请在您的请求中添加更多详细信息.

祝你今天愉快,

阿尔贝托

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....