2016-01-06 36 views
2

我正在開發使用angularJS(客戶端)和mvc web api(服務器)的單頁應用程序。我有兩個物理頁第一的login.html和第二的Index.html 當用戶重定向到index.html,然後我的應用程序負載的其他部分成功登錄到動態與股利ng-view index.html頁面內簽署和我用AngularJS $routeProvider配置我的路線及其相關的模板和控制器。最近我去除散列標籤從URL中使用$locationProvider.html5Mode(true);並添加<base href="/Index.html">頭的Index.html Page.I的部分有當我去到這樣的頁面,第一次每一件事情是罰款採取像這樣Index.html/MetaDetails/123456動態參數的路線,但是當刷新我收到頁面iis的404錯誤從URL中刪除哈希標記iis 404錯誤angularjs應用程序

這裏使用$routeProvider

App.config(function ($routeProvider, $locationProvider) { 
$routeProvider 
.when('/Index.html', { 
    templateUrl: 'View/HomePage.html' 
}) 
    .when('/MetaDetails/:url', { 
     templateUrl: 'View/MetaDetails/MetaDetails.html' 
    }).when('/Logout', { 
     templateUrl: 'View/Users/logout.html', 
     controller: 'LogoutController' 
    }).when('/MetaCRUD', { 
     templateUrl: 'View/MetaDetails/MetaCRUD.html', 
     typeTemplate:'insert', 
     controller: 'MetaCRUDController' 
    }).when('/MetaCRUD/:url', { 
     templateUrl: 'View/MetaDetails/MetaCRUD.html', 
     typeTemplate: 'update', 
     controller: 'MetaCRUDController' 
    }).when('/MetaReport', { 
     templateUrl: 'View/Report/MasterReport.html', 
     controller: 'reportController' 
    }) 
    .when('/404', { 
     templateUrl: 'View/ErrorPage.html', 

    }) 
    .otherwise({ 

     redirectTo: '/404' 
    }); 

$locationProvider.html5Mode(true); 
我的路由配置

});

我知道這是因爲它與IIS路由衝突,知道我是一個真正的物理頁所以最有可能的解決辦法是URL重寫路線我用以下重寫規則

<rule name="AngularJS Routes" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAll"> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="/" /> 
    </rule> 
    </rules> 

更新2:

然後當我刷新或從其他URL重定向我的路線不會改變,但顯示的index.html沒有它的CSS的JS refrences包括(完全毀壞),就好像它沒有CSS和JS和它基本上是因爲它試圖從主機/ metadetails/example.css或host/metade讀取資源尾巴/ example.js而不是主機/ example.js 它是如何發生的,我怎樣才能使它從根不/ metadetals路徑獲取資源

你認爲什麼是合適的解決方案(這可能是一個iis url rewriting)來解決這個問題

請注意,當我從一個頁面導航到另一個頁面時,例如從metaCRUD(index.html/MetaCRUD)到所需的頁面,保持單頁結構對我來說非常重要MetaDetails(的index.html/MetaDetails/someid) 我不希望我的網頁之中後在所有回就像當我用哈希標籤,它的每一件事情是沒有改變的POS罰款,只模板和數據丁字褲

更新3

我只是弄清楚,問題就出現了,只有當我的路由具有參數(的index.html/MetaDetails/someid)

我怎麼可以重寫URL以便使IIS不會誤認爲我的參數包含路由爲物理路徑?

任何幫助,將不勝感激

+0

請給我一些幫助,我真的需要它 –

+0

嗨你有任何解決方案 – Mohsin

回答

0

很高興大家如何告訴你如何刪除主題標籤,但不刷新的修復。

下面是我工作:

  1. app.js:添加 「$ locationProvider.html5Mode(真);」在app.config中作爲第一行。
  2. index.html:在你的第一行添加「」。
  3. web.config文件:添加以下內容在你的配置結束:

<system.webServer> 
 
     <rewrite> 
 
      <rules> 
 
      <rule name="AngularJS Routes" stopProcessing="true"> 
 
       <match url=".*" /> 
 
       <conditions logicalGrouping="MatchAll"> 
 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
 
       <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> 
 
       </conditions> 
 
       <action type="Rewrite" url="/" /> 
 
      </rule> 
 
      </rules> 
 
     </rewrite> 
 
     </system.webServer>

這爲我工作。道歉,編輯有點喜怒無常。