部署Angular 4 IIS错误“403 - 禁止访问:访问被拒绝。”

问题描述 投票:0回答:2

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

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

我正在使用的网址是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
2个回答
1
投票

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

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

另外我需要更新重写

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

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


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.