2016-01-13 68 views
0

所以我一直在为我的Angular.js应用程序和IIS重写而苦苦挣扎。我有我的网站坐在http://server/jwb/文件夹。我将它重写为/ jwb /中的index.html文件,并且我在index.html中有一个。问题是,当我导航到http://server/jwb/parties/12345时,通过角度完成时看起来很好,但是当我在浏览器上进行刷新时,我失去了CSS和javascript。我看在控制台,他们正在被重写到http://server/jwb/parties/js/nameoffile.js等。我想要做的是告诉IIS重写总是看到他们真正居住在哪里的js,css和img文件,这是http://server/jwb/js,http://server/jwb/csshttp://server/jwb/imgIIS Rewrite在刷新时失去Angular应用程序的路径

什么是重写规则,将为我做到这一点?有没有比使用重写规则更好的方法?

我现在有这个在我的web.config:

<rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="^index\.html" ignoreCase="false" /> 
     <action type="None" /> 
    </rule> 
    <rule name="Imported Rule 2" stopProcessing="true"> 
     <match url="." ignoreCase="false" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="index.html" /> 
    </rule> 
</rules> 

然而,这仍然不奇怪的事情。我甚至做了一些测试,相对路径,这里是我的发现:

现在我们已经测试引用文件下列方式:

<link rel="stylesheet" href="css/bootstrap.css" /> 

OR

<link rel="stylesheet" href="/css/bootstrap.css" /> 

OR

<link rel="stylesheet" href="./css/bootstrap.css" /> 

<link rel="stylesheet" href="../css/bootstrap.css" /> 

而他们都没有工作。下面显示了当我们使用每个文件引用我们的应用程序的路径时会发生什么。为了便于讨论,我们的路径如下:

index --> http://10.34.34.46/jbvdev/calendar 
documents --> http://10.34.34.46/jbvdev/documents/BC498484 
caseNotes --> http://10.34.34.46/jbvdev/casenotes/CV/LA%20/2081/BC498484 

enter image description here

+0

尝试添加基本标记或在页面本身中使用资源的绝对路径 – charlietfl

+0

''link rel =“stylesheet”href =“/ css/bootstrap.css”/>'实际上是一个绝对路径...寻找css目录在网站的根目录。最前面的'/'告诉浏览器以根目录开始,或者任何基本标签定义为root – charlietfl

回答

1

我有完全一样的问题...和做所有加入碱裁判之类的东西被其他地方的建议后,仍然有完全相同同样的问题。

所以是的,请在您的index.html或任何页面为您的角度应用程序的基础添加一个基准ref“/”。然后,你需要恢复到好的正则表达式...

我玩了一段时间才能在正确的位置获得正确的位,并捕获正确的部分....所以你需要咀嚼它你的...

对我来说,我的路径是

  1. /Content/blah.whatever的HTML文件和CSS和
  2. /Scripts/some.js等,为我的javascript

发生了什么事ing正在刷新仅在应用程序路径被插入/ Content或/ Scripts之前...下面是最终为我修复的一组规则...

<rewrite> 
    <rules> 
    <rule name="Removevesseldetailsscripts" stopProcessing="true"> 
     <match url="^(.*[/])Scripts/(.*)$" /> 
     <conditions> 
     </conditions> 
     <action type="Redirect" url="Scripts/{R:2}" /> 
    </rule> 
    <rule name="Removevesseldetailscontent" stopProcessing="true"> 
     <match url="^(.*[/])Content/(.*)$" /> 
     <conditions> 
     </conditions> 
     <action type="Redirect" url="Content/{R:2}" /> 
    </rule> 
    <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> 

的R:2位是把角回路由在url在正确的位置,显然是有R:1,以及其中所捕获的实际路径的根...

有一个戏剧,让我知道,如果我可以有任何更多的帮助!祝你好运!!!

+0

这很好用!我不确定所有这些其他重写规则在哪里浮动,但这看起来似乎是防弹的!使用它的Anyoen,一定要把行为规则指向你的应用程序真正位于的地方,加上index.html(或者你称之为主页的任何东西)。 –