2017-10-18 210 views
0

我使用IIS版本6.1 SP1將我的Angular項目部署到我們的開發環境,並且在路由參數上收到403 Forbidden錯誤。在我的URL中,「客戶端」不是一個組件,而是一個路由參數。該項目在我的本地主機上工作得很好,只是當我將代碼推送到我們的開發環境時纔會出現問題。Angular 4 403使用IIS禁用路由參數

enter image description here 這是我在app.routes.ts代碼:

const routes: Routes = [ 
    { 
     path: '', 
     redirectTo: 'login', 
    pathMatch: 'full' 
}, 
{ 
    path: 'login', 
    component: LoginComponent 
}, 
{ 
    path: 'login/:licenseeCode', 
    component: LoginComponent 

}, 
... 
+1

我不認爲角路由是足夠的信息告訴你問題出在哪裏或是什麼。這看起來很好;你甚至沒有任何可能阻止人們查看組件的警衛。如果它在本地和生產環境中不同,它顯然是應用程序外部的一些東西。 – jonrsharpe

回答

1

如果部署到一個文件夾(不是root),你可能需要調整您的

<base href="/FOLDER_WHERE_YOU_DEPLOYED/" /> 

也嘗試添加這對你的配置文件:

<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="/FOLDER_WHERE_YOU_DEPLOYED/" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
+0

這正是我剛發現的。當我建立我的項目時,我不得不添加--base-href/LPPortal2 /並相應地修改了重寫。謝謝 –