Asp.net mvc IIS 8.x虚拟目录上的Angular应用程序具有奇怪的URL行为

Asp.net mvc IIS 8.x虚拟目录上的Angular应用程序具有奇怪的URL行为,asp.net-mvc,angularjs,iis,Asp.net Mvc,Angularjs,Iis,我在使用MVC的IIS8.x上使用AngularJS时遇到问题。我的带有虚拟目录的应用程序索引页如下所示: https://myapp.xyz/VirtualDirectory/ 该页面加载angular应用程序。我的角度路线设置为: $routeProvider .when('/', { templateUrl: 'Content/Partials/Home/Index.html' }) .when('/Error', { templateUrl: 'Content/Part

我在使用MVC的IIS8.x上使用AngularJS时遇到问题。我的带有虚拟目录的应用程序索引页如下所示:

https://myapp.xyz/VirtualDirectory/
该页面加载angular应用程序。我的角度路线设置为:

$routeProvider
.when('/', {
    templateUrl: 'Content/Partials/Home/Index.html'
})
.when('/Error', {
    templateUrl: 'Content/Partials/Shared/Error.html'
})
.otherwise({
    redirectTo: '/Error'
});
因此,如果我访问第一个链接,我的URL如下所示:

https://myapp.xyz/VirtualDirectory/#/
这很好地解决了我的问题。Angular请求包含虚拟目录的分区,因此我看到一个HTTP请求:

https://myapp.xyz/VirtualDirectory/Content/Partials/Home/Index.html
但是,如果我访问时没有尾部斜杠,如:

https://myapp.xyz/VirtualDirectory
角度路由到:

https://myapp.xyz/VirtualDirectory#/
一旦发生这种情况,我的任何路由都无法工作(它们不尊重虚拟目录)。它们的路线如下:

https://myapp.xyz/Content/Partials/Home/Index.html

这会中断指令中定义的所有路由和模板。有关于如何解决此问题的建议吗?

尝试将此添加到您的head标签中

<html>
<head>
    <base href="/VirtualDirectory/">
</head>
<body>
    ...
</body>

...

我发现,如果对路径使用./syntax,就不需要使用Razor

失败的代码:

$routeProvider.when("/productList", {
            templateUrl: "/app/products/productListView.html", controller: "ProductListController as vm"
        });
有效代码:(注意.before/app)


如何定义路由?我将编辑模板URL以显示完整的路由示例。这不会改变任何内容。我撒谎,这解决了问题。然而,我使用了:
为了进一步添加,我实际上必须使用
才能获得正确的基本URL。
$routeProvider.when("/productList", {
            templateUrl: "./app/products/productListView.html", controller: "ProductListController as vm"
        });