Angular 4 403 Forbidden on route parameter with IIS

流过昼夜 提交于 2020-06-26 19:47:43

问题


I deployed my Angular project to our dev environment using IIS Version 6.1 SP1 and I'm getting 403 Forbidden error on my route parameter. In my URL, the "client" is not a component but a route parameter. The project works perfectly fine on my localhost, the issue is only when I pushed the code to our development environment.

Here is my code in app.routes.ts:

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

},
...

回答1:


if you deployed to a folder (NOT ROOT) you might need to adjust your

<base href="/FOLDER_WHERE_YOU_DEPLOYED/" />

also try adding this to your config file:

<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>


来源:https://stackoverflow.com/questions/46812148/angular-4-403-forbidden-on-route-parameter-with-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!