Angularjs 如何添加尾随斜杠以固定角度指令引用

Angularjs 如何添加尾随斜杠以固定角度指令引用,angularjs,mod-rewrite,iis,Angularjs,Mod Rewrite,Iis,我们正在开发一个Angular应用程序,该应用程序位于IIS虚拟目录中 因此,应用程序的url是:https://domain.com/department/myapp 默认情况下,IIS不会在此url中添加尾随斜杠,因此当ui router添加路由路径时,它将变为https://domain.com/department/myapp#/home而不是https://domain.com/department/myapp/#/home 它在最新的浏览器中运行良好,但对于IE9来说,它会导致一个问

我们正在开发一个Angular应用程序,该应用程序位于IIS虚拟目录中

因此,应用程序的url是:
https://domain.com/department/myapp

默认情况下,IIS不会在此url中添加尾随斜杠,因此当
ui router
添加路由路径时,它将变为
https://domain.com/department/myapp#/home
而不是
https://domain.com/department/myapp/#/home

它在最新的浏览器中运行良好,但对于IE9来说,它会导致一个问题

我的所有指令都要求从相对url获取模板。如果在
#
字符之前没有尾随斜杠,则指令声明中的
模板URL
无法获取模板html


昨天我想我可以通过在IIS中重写url来添加尾随斜杠。因此,在我的
Web.Config
中,我添加了:

<defaultDocument enabled="false"></defaultDocument>
<rewrite>
  <rules>
    <rule name="add trailing slash" stopProcessing="true">
      <match url="(.*[^/])$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
    </rule>
  </rules>
</rewrite>

当然,我也在我的IIS上安装了
urlrewrite2

结果如何?这个重写规则破坏了我对缩小的js和css包的链接。而我所需要的只是正确地获取对我的
app
文件夹的引用


现在我坐下来,试图找到一个合适的方法来修复它

可能需要更新规则的
匹配url
,以有选择地避免损坏我对这些捆绑包的引用

AngularJS$location服务是否可以在客户端添加尾随斜杠


有什么建议吗?提前谢谢。

好的。这是我到目前为止发现的

该解决方案既不涉及url重写,也不涉及angular
$location
服务。我在
Global.asax
应用程序中添加了url检查和重定向

代码如下:

    protected void Application_BeginRequest()
    {
        if (!NeedToProcess(Request.ApplicationPath, Request.Path)) return;
        var redirectPath = VirtualPathUtility.AppendTrailingSlash(Request.ApplicationPath);
        Response.RedirectPermanent(redirectPath);
    }

    private static bool NeedToProcess(string appPath, string reqPath)
    {
        return appPath != null &&
               appPath != "/" &&
               appPath.Equals(reqPath, StringComparison.OrdinalIgnoreCase);
    }
如果任何人有更好的解决方案,请随时添加到这里