Angular 4 403 禁止使用 IIS 的路由参数
Angular 4 403 Forbidden on route parameter with IIS
我使用 IIS 版本 6.1 SP1 将我的 Angular 项目部署到我们的开发环境,我在我的路由参数上收到 403 Forbidden 错误。在我的 URL 中, "client" 不是组件而是路由参数。该项目在我的本地主机上运行良好,问题仅出现在我将代码推送到我们的开发环境时。
这是我在 app.routes.ts:
中的代码
const routes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
{
path: 'login/:licenseeCode',
component: LoginComponent
},
...
如果您部署到一个文件夹(非 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>
我使用 IIS 版本 6.1 SP1 将我的 Angular 项目部署到我们的开发环境,我在我的路由参数上收到 403 Forbidden 错误。在我的 URL 中, "client" 不是组件而是路由参数。该项目在我的本地主机上运行良好,问题仅出现在我将代码推送到我们的开发环境时。
const routes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: 'login',
component: LoginComponent
},
{
path: 'login/:licenseeCode',
component: LoginComponent
},
...
如果您部署到一个文件夹(非 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>