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

时间:2016-06-16 23:47:45

标签: javascript jquery angularjs asp.net-mvc routing

我正在尝试使用源代码学习一些东西,但当我尝试复制自己的代码时,我收到了这个错误。

我有一个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,或者我错过了一些软件包?

尝试在浏览器中查看一个模板并出现另一个错误:

  '/'应用程序中的服务器错误。       不提供此类型的页面。

     

描述:未提供您请求的页面类型,因为它已被明确禁止。扩展名“.cshtml”可以   不对。请查看下面的网址,确保它是   拼写正确。

     

请求的网址:/ Messages/Templates/Create.cshtml

1 个答案:

答案 0 :(得分:5)

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

以下是解决方案:Server Error in '/' Application. This type of page is not served

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

我在webconfig中设置为false