javascript – 无法加载资源:服务器响应状态为403(禁止)MVC 5

我试图用源代码学习一些东西但是当我尝试复制自己这个代码时,我收到了这个错误.

我有一个View Index,我试图从另一个文件夹访问一些.cshtml模板.

@{
    ViewBag.Title = "Index";
}
<div ng-controller="inboxIndexCtrl">
    <div class="row">
        <div class="col-sm-1">
            <a ng-href="#/" id="InboxSubNav">Inbox</a>
            <hr />
            <a ng-href="#/sent" id="InboxSubNav">Sent</a>
            <hr />
            <a ng-href="#/create" id="InboxSubNav">Create</a>
        </div>
        <div class="col-sm-11">

            <div class="well" ng-view></div>

        </div>

    </div>
</div>

脚本:

var mail = angular.module('mail', ['ngRoute']);

mail.config([
    '$routeProvider', ($routeProvider) => {
        $routeProvider.when('/', {
            templateUrl: 'Templates/Incoming.cshtml'
        })
            // Registering path with controller relative to Inbox/Index
            // This part is similar to RouteConfig.cs in ASP MVC
            .when('/message/:id', {
                // Templates are located inside Inbox.
                templateUrl: 'Templates/Message.cshtml',
                controller: 'oneMessageCtrl'
            }).when('/create', {
                templateUrl: 'Templates/Create.cshtml',
                controller: 'createCtrl'
            }).when('/reply/:id', {
                templateUrl: 'Templates/Reply.cshtml',
                controller: 'replyCtrl'
            }).when('/sent', {
                templateUrl: 'Templates/Sent.cshtml',
                controller: 'sentCtrl'
            })

            .otherwise({ redirectTo: '/' });

    }
]);

_Layout已包含ng-app< html ng-app =“mail”>.此外,Angular bundle在Jquery之前加载,这是通过localhost完成的.

我正在使用的版本:

Angular 1.3.0-beta4
jquery-1.10.2

当页面加载时,它会加载< div class =“well”ng-view>< / div>然后消失.

当我将鼠标悬停在链接上方时,路径似乎没问题.当我点击链接时,它会进入路径但由于403错误而未加载任何内容.

这里有一些链接:

http://localhost:49602/Messages/Index#/
http://localhost:49602/Messages/Index#/sent
http://localhost:49602/Messages/Index#/create

我的猜测是我没有使用正确版本的Angular / Jquery,或者我错过了一些软件包?

试图在浏览器中查看一个模板并得到另一个错误:

Server Error in ‘/’ Application.
This type of page is not served.

Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension ‘.cshtml’ may
be incorrect. Please review the URL below and make sure that it is
spelled correctly.

Requested URL: /Messages/Templates/Create.cshtml

解决方法:

在*的帮助下,我解决了这个问题:

这是解决方案:Server Error in ‘/’ Application. This type of page is not served

<add key="webpages:Enabled" value="true" />

它在我的webconfig中设置为false

上一篇:linux – 如何将容器上的localhost端口转发到主机上的localhost?


下一篇:php – codeigniter 2:默认控制器上出现404错误