【发布时间】:2016-10-18 17:03:08
【问题描述】:
我正在关注这篇文章(关于使用 URL 重写的底部部分)。我的 IIS Express(从 VS 启动)配置文件似乎位于 C:\Users[usernamehere]\documents\IISexpress\applicationhost.config。
我将重写规则放在<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 放在根目录下,并将我的测试视图放在 Views 文件夹下。这是 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?
【问题讨论】:
标签: asp.net angularjs asp.net-mvc iis-express