我試圖讓Angular ui-route在IIS7上部署,但即使使用URL重寫web.config中的設置,它仍然不像IIS Express中那樣完美。Angular-UI-Router和IIS發佈
404狀態總是由IIS截獲並顯示
404 - 文件或目錄未找到。 您正在查找的資源可能已被刪除,名稱已更改或暫時不可用。
但我的路由器處理404重定向罰款,並正確加載模板時,使用iis express。
角配置
.config(["$stateProvider", "$locationProvider", "growlProvider", "$urlRouterProvider", function ($stateProvider, $locationProvider, growlProvider, $urlRouterProvider) {
// UI States, URL Routing & Mapping. For more info see: https://github.com/angular-ui/ui-router
// ------------------------------------------------------------------------------------------------------------
// the known route, with missing '/' - let's create alias
$urlRouterProvider.when("", "/");
$stateProvider
.state("home", {
url: "/",
templateUrl: urlbase + "/views/login",
controller: "LoginCtrl"
})
.state("modal", {
url: "/modal",
templateUrl: urlbase + "/views/modal",
controller: "ModalCtrl"
})
.state("about", {
url: "/about",
templateUrl: urlbase + "/views/about",
controller: "AboutCtrl"
})
.state("index", {
url: "/index",
templateUrl: urlbase + "/views/index",
controller: "IndexCtrl"
})
.state("login", {
url: "/login",
//layout: "basic",
templateUrl: urlbase + "/views/login",
controller: "LoginCtrl"
})
.state("404", {
url: "{path:.*}",
templateUrl: urlbase + "/views/404",
controller: "Error404Ctrl"
});
$locationProvider.html5Mode(true);
growlProvider.globalTimeToLive(3000);
}])
web.config中的URL重寫
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<staticContent>
<clear />
<mimeMap fileExtension=".xml" mimeType="text/x-cross-domain-policy" />
</staticContent>
</system.webServer>
我失去了一些東西在這裏?謝謝!
錯誤表示您嘗試訪問一個資源,但他沒有找到它。你確定所有的模板都可用嗎? – carton
是的100%肯定,當我在瀏覽器中硬編碼相對路徑時,我可以訪問所有模板。並且路由在iis中完美地工作,所以它必須與IIS – Brandonm