Javascript 无法加载资源:服务器响应状态为 403(禁止)MVC 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37871091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to load resource: the server responded with a status of 403 (Forbidden) MVC 5
提问by Eduard
I am trying to learn some things with a source code but when I try to replicate myself this code I am getting that error.
我正在尝试使用源代码学习一些东西,但是当我尝试自己复制此代码时,我收到了该错误。
I have a View Indexwhere I am trying to access some .cshtml Templates from another folder.
我有一个视图索引,我试图从另一个文件夹访问一些 .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>
Script:
脚本:
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 have included ng-app<html ng-app="mail">
. Also Angular bundle is loaded before Jquery, and this is done with localhost.
_Layout 包含了 ng-app <html ng-app="mail">
。此外,Angular 包是在 Jquery 之前加载的,这是通过 localhost 完成的。
Versions I am using:
我正在使用的版本:
Angular 1.3.0-beta4
jquery-1.10.2
When the page loads, for a second it loads the <div class="well" ng-view></div>
then dissapear.
当页面加载时,它加载一秒钟<div class="well" ng-view></div>
然后消失。
When I hover the mouse above the links the path seems to be fine. When I click on links it goes on path but doesn't load anything due to 403 error.
当我将鼠标悬停在链接上方时,路径似乎没问题。当我点击链接时,它会进入路径,但由于 403 错误而没有加载任何内容。
Here some the links:
这里有一些链接:
http://localhost:49602/Messages/Index#/
http://localhost:49602/Messages/Index#/sent
http://localhost:49602/Messages/Index#/create
My guess is that I am not using the right versions of Angular/Jquery or am I missing some packages?
我的猜测是我没有使用正确版本的 Angular/Jquery 或者我是否缺少一些包?
Tried to View in browser one Template and got another error:
试图在浏览器中查看一个模板并得到另一个错误:
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
“/”应用程序中的服务器错误。不提供此类页面。
描述:您请求的页面类型未被提供,因为它已被明确禁止。扩展名“.cshtml”可能不正确。请检查下面的 URL 并确保其拼写正确。
请求的 URL:/Messages/Templates/Create.cshtml
采纳答案by Eduard
Well with the help from stackoverflow I solved the problem:
在stackoverflow的帮助下,我解决了这个问题:
Here is the solution: Server Error in '/' Application. This type of page is not served
这是解决方案:“/”应用程序中的服务器错误。不提供此类页面
<add key="webpages:Enabled" value="true" />
It was set on false in my webconfig
它在我的 webconfig 中设置为 false