使用 IIS Express 在 AngularJS 项目中出现 403 错误

兴奋性

在 AngularJS 中,我试图设置一个主页,其中列出了我的 app/data/event 文件夹中的事件(json 文件)。控制器 EventListController 如下所示:

'use strict';

eventsApp.controller('EventListController', 
    function EventListController($scope, $location, eventData) {
        $scope.events = eventData.getAllEvents();
})

EventData 服务如下所示:

eventsApp.factory('eventData', function ($resource) {
    var resource = $resource('/app/data/event/:id', { id: '@id' }, { "getAll": { method: "GET", isArray: true, params: { something: "foo" } } });
    return {
        getEvent: function (eventId) {
            return resource.get({
                id: eventId
            });
        },
        typeOf: function (obj) {
            return {}.toString.call(obj).split(' ')[1].slice(0, -1).toLowerCase();
        },
        getAllEvents: function () {
            return resource.query();
        },
        save: function (event) {
            return resource.save(event);
        }
    };

EventList.html 看起来像这样:

<div>
    <h1>Events</h1>
    <hr/>
    <hr/>
    <ul class="thumbnails">
        <li ng-repeat="event in events|orderBy:sortorder" class="span5">
            <event-thumbnail/>
        </li>
    </ul>

</div>

我的路线如下所示:

'use strict';

var eventsApp = angular.module('eventsApp', ['ngResource', 'ngRoute'])
    .config(function ($routeProvider) {
        $routeProvider.when('/newEvent',
            {
                templateUrl: '/app/templates/NewEvent.html',
                controller: 'EditEventController'
            });
        $routeProvider.when('/eventDetails/:eventId',
           {
               templateUrl: '/app/templates/EventDetails.html',
               controller: 'EventController'
           });
        $routeProvider.when('/profile',
            {
                templateUrl: '/app/templates/EditProfile.html',
                controller: 'EditProfileController'
            });
        $routeProvider.when('/events',
            {
                templateUrl: '/app/templates/EventList.html',
                controller: 'EventListController'
            });
        $routeProvider.otherwise({ redirectTo: '/events' });
    });

WebAPI 控制器(在单独的 WebAPI 项目中)EventController.cs 如下所示:

public class EventController : ApiController
    {
       public JToken Get(string id = null)
        {
            if (id==null)
            {
                return GetAllJsonEventsAsArray();
            }
            return GetSingleJsonFile(id);
        }
private JArray GetAllJsonEventsAsArray()
        {
            var path = System.Web.Hosting.HostingEnvironment.MapPath("/");
            var contents = "";
            foreach (var file in System.IO.Directory.GetFiles(path + "..app/data/event/"))
            {
                contents += System.IO.File.ReadAllText(file) + ",";
            }

            return JArray.Parse("[" + contents.Substring(0, contents.Length - 1) + "]");
        }

最后,WebApiConfig.cs 看起来像这样:

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }

当我尝试访问http://localhost:49403/app/#/events 时出现错误:GET http://localhost:49403/app/data/event/ 403 (Forbidden)

有人能帮忙吗?任何帮助都感激不尽。有的 

兴奋性

IIS 网站中的 configuration/system.webServer/directoryBrowse@enabled 默认设置为 False。将其设置为 True 使我的应用程序能够浏览目录。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WCF IIS错误403

来自分类Dev

CORS 403错误Angular和Express

来自分类Dev

更新Android SDK后,我的项目中出现很多错误

来自分类Dev

在IIS8 Express上运行ServiceStack时出现404 Not Found错误

来自分类Dev

使用htaccess进行seo友好链接时出现403错误

来自分类Dev

使用ngAudio时出现AngularJS错误

来自分类Dev

使用appcompat v7时项目中出现Android错误

来自分类Dev

使用AngularJS时出现“ .then()不是函数”错误

来自分类Dev

Visual Studio 2015 IIS Express 500错误

来自分类Dev

UnsatisfiedLinkError:在电报项目中出现此错误

来自分类Dev

HTTP错误405.0-IIS Express中不允许使用此方法

来自分类Dev

本地azure devops build agent出现403错误-其他项目中的其他build正常运行

来自分类Dev

尝试在我的项目中使用UIKit但出现错误

来自分类Dev

使用IIS Express和Visual Studio调试项目时出现持久访问拒绝消息

来自分类Dev

使用Spring Security时出现意外的403错误

来自分类Dev

如何使用IIS Express 10?

来自分类Dev

我的SharedPreferences项目中出现错误

来自分类Dev

奇怪的错误403:在SharePoint 2013 IIS中禁止访问

来自分类Dev

在IIS8 Express上运行ServiceStack时出现404 Not Found错误

来自分类Dev

使用splice()时出现AngularJS错误

来自分类Dev

在Visual Studio 2015中启动Web项目时出现IIS Express 10(64位)错误

来自分类Dev

使用Appcompat v7时项目中出现Android错误

来自分类Dev

配置IIS Express失败,出现以下错误:无法访问IIS配置数据库

来自分类Dev

错误401和403仅在Internet Explorer中出现(而不在Chrome,Firefox,..中出现)-IIS配置?

来自分类Dev

添加Cocoapods后在iOS项目中出现构建错误?

来自分类Dev

403错误,并显示消息“项目之前未在项目中使用Google Slides API或已将其禁用”

来自分类Dev

使用 PPA 出现 403 错误

来自分类Dev

AngularJS 5 在项目中的使用

来自分类Dev

使用 angular-azure-blob-service 时出现 403 错误

Related 相关文章

  1. 1

    WCF IIS错误403

  2. 2

    CORS 403错误Angular和Express

  3. 3

    更新Android SDK后,我的项目中出现很多错误

  4. 4

    在IIS8 Express上运行ServiceStack时出现404 Not Found错误

  5. 5

    使用htaccess进行seo友好链接时出现403错误

  6. 6

    使用ngAudio时出现AngularJS错误

  7. 7

    使用appcompat v7时项目中出现Android错误

  8. 8

    使用AngularJS时出现“ .then()不是函数”错误

  9. 9

    Visual Studio 2015 IIS Express 500错误

  10. 10

    UnsatisfiedLinkError:在电报项目中出现此错误

  11. 11

    HTTP错误405.0-IIS Express中不允许使用此方法

  12. 12

    本地azure devops build agent出现403错误-其他项目中的其他build正常运行

  13. 13

    尝试在我的项目中使用UIKit但出现错误

  14. 14

    使用IIS Express和Visual Studio调试项目时出现持久访问拒绝消息

  15. 15

    使用Spring Security时出现意外的403错误

  16. 16

    如何使用IIS Express 10?

  17. 17

    我的SharedPreferences项目中出现错误

  18. 18

    奇怪的错误403:在SharePoint 2013 IIS中禁止访问

  19. 19

    在IIS8 Express上运行ServiceStack时出现404 Not Found错误

  20. 20

    使用splice()时出现AngularJS错误

  21. 21

    在Visual Studio 2015中启动Web项目时出现IIS Express 10(64位)错误

  22. 22

    使用Appcompat v7时项目中出现Android错误

  23. 23

    配置IIS Express失败,出现以下错误:无法访问IIS配置数据库

  24. 24

    错误401和403仅在Internet Explorer中出现(而不在Chrome,Firefox,..中出现)-IIS配置?

  25. 25

    添加Cocoapods后在iOS项目中出现构建错误?

  26. 26

    403错误,并显示消息“项目之前未在项目中使用Google Slides API或已将其禁用”

  27. 27

    使用 PPA 出现 403 错误

  28. 28

    AngularJS 5 在项目中的使用

  29. 29

    使用 angular-azure-blob-service 时出现 403 错误

热门标签

归档