【问题标题】:Deploy Angular 4 IIS error "403 - Forbidden: Access is denied."部署 Angular 4 IIS 错误“403 - 禁止访问:访问被拒绝。”
【发布时间】:2017-10-17 19:51:49
【问题描述】:

我正在尝试在 IIS 服务器上部署 Angular 4 网站,但出现此错误

“403 - 禁止访问:访问被拒绝。”

我使用的 URL 是 http://domain/LpPortal2/login/client 并且“客户端”不是我的 Angular 项目中的实际组件,它是让我的登录页面知道要在页面上显示哪些徽标和颜色。这是我的 app.routes.ts 中的代码。

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

这是我的 web.config 以供您参考:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <modules>
      <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" 
type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
    <handlers>
      <remove name="UrlRoutingHandler"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="Angular" 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>
     <staticContent>
    <remove fileExtension=".json" />
    <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
       <defaultDocument>
           <files>
               <remove value="index.php" />
               <remove value="default.aspx" />
               <remove value="iisstart.htm" />
               <remove value="index.htm" />
               <remove value="Default.asp" />
               <remove value="Default.htm" />
            </files>
       </defaultDocument>
  </system.webServer>

感谢您的帮助。

【问题讨论】:

标签: angular iis angular-ui-router web-config webdeploy


【解决方案1】:

所以问题是当我构建我的应用程序时,我需要添加 --base-ref /my-domain-name/ 如下所示:

ng build -env=dev --base-href /LPPortal2/

另外我需要将重写更新为

<action type="Rewrite" url="/LPPortal2" />

这两件事修复了我的 403 错误。

【讨论】:

    【解决方案2】:

    以管理员身份运行 IDE 以打开 Angula 文件夹,它将工作,您可以保存您的工作,因为我遇到了同样的问题并以管理员身份运行 Visual Studio Code(您可以使用任何类型的您喜欢的 IDE)解决了问题.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 2021-08-31
      相关资源
      最近更新 更多