我试图获得角UI路由工作,一旦部署在IIS7但即使URL重写设置在其仍不如理想,因为它在IIS快递工作的web.config。
404状态总是由IIS和显示器截获
404 - 文件或目录未找到。您正在寻找可能已经删除该资源,有其名称更改,或者暂时不可用。
但我的路由器处理404重定向的罚款,并使用IIS表达时正确加载模板。
角配置
.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>
我失去了一些东西在这里?谢谢!
如果有人遇到类似的问题,我通过特别添加自定义错误页的URL为404个状态码,使用“执行本网站的URL”选项解决了这个托管服务器上。
当您打开html5Mode($ locationProvider.html5Mode(真),这种情况会发生。
在AngularJS应用它会从角虚拟的URL的哈希(#)前缀设置html5mode为true,这样做的副作用是,如果你尝试直接导航到深层链接在您的角度应用或刷新您可以在内部网页得到一个404页没有发现错误。
这是我做过什么来解决这个问题。在我的web.config,我只是说剪断下面的代码。上运行的Visual Studio调试模式下应用程序时,它同时适用于IIS服务器。
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS" 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>
</system.webServer>
......other configurations ...
</configuration>