c# - 使用 AngularJS 将 ASP.NET CORE Web 应用程序发布到 IIS

标签 c# angularjs iis asp.net-core asp.net-core-mvc

我们正在编写一个新的 asp.net 核心网络应用程序(具有完整的 .net 框架),使用 angularjs ver。 1.5.8.
我们刚刚开始使用该应用程序,所以它非常简单,只有一个页面包含一个包含学生数据的表格。
现在,当我使用 IIS Express 运行应用程序时,应用程序工作正常,数据显示并且浏览器控制台中没有错误。
但是当我将应用程序发布到我的本地 IIS 时,它不起作用。 Angular View 是空的,所以只显示 _layout。
我已经尝试了 https://docs.asp.net/en/latest/publishing/iis.html 中描述的步骤,但正如我所说,它不起作用。
这是我正在使用的代码:

程序.Main():

public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }  

site.js(棱 Angular 分明的东西):

angular.module('digitalRural', ['ngRoute', 'ngMaterial'])
    .config(function ($routeProvider) {
        $routeProvider
            .when('/',                                                  // Students controller
            {
                controller: 'StudentsController as students',
                templateUrl: 'html/students/index.html'
            })
            .when('/student/edit/:studentId',
            {
                controller: 'EditStudentController as editStudent',
                templateUrl: 'html/students/edit.html'
            })
            .when('/student/new',
            {
                controller: 'NewStudentController as newStudent',
                templateUrl: 'html/students/new.html'
            })
            .when('/login/',                                            // Login controller
            {
                controller: 'LoginController as loginCtrl',
                templateUrl: 'html/home/welcome.html'
            })
            .otherwise({
                redirectTo: '/'
            });
    })
    .controller('StudentsController',
        function ($http) {
            var students = this;

            $http.get("/api/students")
                .then(function (response) {
                    students.items = response.data;
                });
        })
    .controller('LoginController',
        function ($http) {
            var loginCtrl = this;

            $http.get("/api/login")
                .then(function (response) {
                    loginCtrl.currentUser = response.data;
                });
        });  

这是已部署应用程序的图像:
enter image description here

以及 Chrome 控制台中的错误:

Failed to load resource: the server responded with a status of 404 (Not Found)
angular.js:13920 Error: [$compile:tpload] http://errors.angularjs.org/1.5.8/$compile/tpload?p0=html%2Fstudents%2Findex.html&p1=404&p2=Not%20Found
    at Error (native)
    at http://localhost/DigitalRural/lib/angular/angular.min.js:6:412
    at http://localhost/DigitalRural/lib/angular/angular.min.js:156:511
    at http://localhost/DigitalRural/lib/angular/angular.min.js:131:20
    at m.$eval (http://localhost/DigitalRural/lib/angular/angular.min.js:145:347)
    at m.$digest (http://localhost/DigitalRural/lib/angular/angular.min.js:142:420)
    at m.$apply (http://localhost/DigitalRural/lib/angular/angular.min.js:146:113)
    at l (http://localhost/DigitalRural/lib/angular/angular.min.js:97:322)
    at J (http://localhost/DigitalRural/lib/angular/angular.min.js:102:34)
    at XMLHttpRequest.t.onload (http://localhost/DigitalRural/lib/angular/angular.min.js:103:4)  

奇怪的是,在 IIS Express 上一切正常,但在 IIS 上,我收到上面的错误消息。

什么给了?

最佳答案

错误是404,因为你的模块无法加载你的模板,检查你的编译版本在“html/students/”或“html/home/”中是否有这个模板。

关于c# - 使用 AngularJS 将 ASP.NET CORE Web 应用程序发布到 IIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38866784/

相关文章:

c# - Entity Framework 自动外键填充

angularjs - Angular 输入限制为 1 个字符

ASP.NET 站点无法在 IIS 下启动

iis - jsmin 的 CFExecute 失败

c# - 加速嵌套 for 循环并提高性能

c# - 如何在 Windows Phone 8.1(通用)中获取设备的 RAM(512 mb、1GB、2GB)数量?

c# - 拉伸(stretch)图像以填充可用的宽度/高度(单独)

javascript - 输入的总和数组

javascript - 使用 Angular1+ ES6 时, Controller 函数中的依赖注入(inject)未定义, Controller 作为类

asp.net - 已将 'multipart/form-data' 上传到 ASP.NET Web API 操作,在无缓冲模式下不可读