Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将带有AngularJS的ASP.NET核心web应用发布到IIS_C#_Angularjs_Iis_Asp.net Core_Asp.net Core Mvc - Fatal编程技术网

C# 将带有AngularJS的ASP.NET核心web应用发布到IIS

C# 将带有AngularJS的ASP.NET核心web应用发布到IIS,c#,angularjs,iis,asp.net-core,asp.net-core-mvc,C#,Angularjs,Iis,Asp.net Core,Asp.net Core Mvc,我们正在使用angularjs版本编写一个新的asp.net核心web应用程序(具有完整的.net框架)。1.5.8. 我们刚刚开始使用这个应用程序,所以它是非常简单的atm,只有一个页面包含一个包含学生数据的表。 现在,当我使用IIS Express运行应用程序时,应用程序工作正常,显示数据,并且浏览器控制台中没有错误。 但当我将应用程序发布到本地IIS时,它就不起作用了。角度视图为空,因此仅显示_布局。 我已经尝试了中描述的步骤,但正如我所说,它不起作用。 以下是我使用的代码: Progra

我们正在使用angularjs版本编写一个新的asp.net核心web应用程序(具有完整的.net框架)。1.5.8.
我们刚刚开始使用这个应用程序,所以它是非常简单的atm,只有一个页面包含一个包含学生数据的表。
现在,当我使用IIS Express运行应用程序时,应用程序工作正常,显示数据,并且浏览器控制台中没有错误。
但当我将应用程序发布到本地IIS时,它就不起作用了。角度视图为空,因此仅显示_布局。
我已经尝试了中描述的步骤,但正如我所说,它不起作用。
以下是我使用的代码:

Program.Main()

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

            host.Run();
        }  
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;
                });
        });  
以下是已部署应用程序的图像:

以及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/”中包含此模板。

确定,找到问题的原因。
我不知道AngularJS从服务器的根目录引用URL。因此,下面的api调用:
$http.get(“/api/students”)

找不到,因为它缺少服务器根目录:“MyServer/api/students/”
我在这里找到了解决方案:


谢谢大家的回答。他们在其他方面帮助了我:)

angularjs无法找到所需的模板文件。查看浏览器的“网络”选项卡。您将看到大量404错误。请检查是否在项目的“publishOptions”部分包含了所有必需的文件。jsonI将包含目录的屏幕截图,以便您可以帮助我确定是否缺少某些内容。谢谢/正如您所看到的,在这个文件夹中只存在一个文件“index”,在这里您应该有文件“edit.html”和“new.html”从您的源代码复制这个文件,html文件不需要编译。