我在關注這篇文章(關於使用URL Rewrite的底部部分)。我的IIS Express(從VS啓動)配置文件似乎位於C:\ Users [usernamehere] \ documents \ IISexpress \ applicationhost.config。重寫angular和ASP.NET MVC的規則
我把重寫規則放在<system.webServer>
標籤裏面,就像那篇文章(和我讀過的很多其他文章)說的那樣。所以它看起來像:
<system.webServer>
<rewrite>
<rules>
<rule name="angularjs routes"
stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}"
pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
... all the other crap that was already there
</system.webServer>
在我的VS項目中我有index.htm關閉根和我的測試視圖下一個視圖文件夾。這是index.htm,當我點擊鏈接時,它工作正常。
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<head>
<base href="/">
<title></title>
<meta charset="utf-8" />
</head>
<body ng-app="myApp">
<p><a href="/">Main</a></p>
<a href="red">Red</a>
<a href="green">Green</a>
<a href="blue">Blue</a>
<!-- below is where the partial pages will replace -->
<div ng-view></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when("/red", {
templateUrl: "Views/red.htm",
controller: "redController"
})
.when("/green", {
templateUrl: "Views/green.htm",
controller: "greenController"
})
.when("/blue", {
templateUrl: "Views/blue.htm",
controller: "blueController"
});
$locationProvider.html5Mode(true);
});
app.controller("redController", function($scope){
//alert("Red");
});
app.controller("blueController", function ($scope) {
//alert("Blue");
});
app.controller("greenController", function ($scope) {
//alert("Green");
});
</script>
</body>
</html>
問題是當我嘗試在這些頁面上的一個輸入:即。 http://localhost:60553/red
我得到一個404.這告訴我,重寫規則沒有被擊中,並做它的工作。爲什麼即使使用該重寫規則,我也會得到404?
看不到。我創建了一個空白的Web項目,所以沒有安裝MVC的東西。這是我的處理程序部分在web.config中的樣子。 <除去名稱= 「ExtensionlessUrlHandler集成-4.0」/> <除去名稱= 「OPTIONSVerbHandler」/> <除去名稱= 「TRACEVerbHandler」/> <添加名稱= 「ExtensionlessUrlHandler集成-4.0」 路徑= 「*」。動詞= 「*」 類型= 「System.Web.Handlers.TransferRequestHandler」 前提= 「integratedMode,runtimeVersionv4.0」/> –
user441521
此外,我能夠在地址欄中mysite.com/Views/red鍵入。 HTM並返回頁面。顯然,它不會運行任何角度,所以你看到所有的括號,但它允許我去那裏,所以沒有權限問題。 – user441521
那聽起來不像重寫問題。如果重寫是問題,則手動瀏覽時您無法訪問網址。 –