在AZURE

时间:2018-03-12 09:48:43

标签: asp.net json api azure web

我创建了一个asp.net api应用程序,它从JSON文件中读取数据并将其显示在表格中。当我从visual studio运行它时,它成功地读取数据并显示它,但是在我上传到Azure后,表格是空的。

我把它存放在" jsondata"文件夹和调用是这样的:

var request = {
            method: 'get',
            url: '../jsondata/data.json',
            dataType: 'json',
            contentType: "application/json"
        };

目:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>

身体:

<div ng-app="myApp"
        ng-controller="myController">

       <table class="table table-bordered table-hover">
           <thead>
               <tr>
                   <th>ID</th>
                   <th>Furniture Piece</th>
                   <th>Category</th>
                   <th>Price</th>
               </tr>
           </thead>

           <tbody>
              <tr ng-repeat="furniture in list">
                   <td>{{furniture.ID}}</td>
                   <td>{{furniture.Name}}</td>
                   <td>{{furniture.Type}}</td>
                   <td>{{furniture.Price}}</td>
               </tr>
           </tbody>

       </table>
</div>

使用angular:

读取json文件的脚本
<script>

var app = angular.module('myApp', []);
app.controller('myController',
    function ($scope, $http) {

        var request = {
            method: 'get',
            url: '../jsondata/data.json',
            dataType: 'json',
            contentType: "application/json"
        };

        $scope.arrFurniture = new Array;

        $http(request)
            .success(function (jsonData) {
                $scope.arrFurniture = jsonData;
                $scope.list = $scope.arrFurniture;
            })
            .error(function () {

            });
    });
</script>

1 个答案:

答案 0 :(得分:1)

要从Azure App Service提供静态.json文件,您需要将以下mimeMap添加到web.config文件中:

<?xml version="1.0"?>

<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
    </system.webServer>
</configuration> 

参考:How to serve static .json files from a Windows Azure Website