在IIS上的虚拟目录下运行Angular8(无法访问内部链接)

在IIS上的虚拟目录下运行Angular8(无法访问内部链接),iis,angular8,virtual-directory,Iis,Angular8,Virtual Directory,这个问题与第8条有关 我有一个在IIS上运行的网站,代码在.Net中,AngularJs 1.6说www.parent.com 我正在用纯Angular 8(单页应用程序)构建一个全新的网站,目前拥有www.parent.com项目的一些页面。我还必须在同一个域上运行它们。因此,我试图在虚拟目录中托管新网站 我尝试的是: 创建了一个虚拟目录,比如说/v2 使用ng build--base href”/v2--deploy url”/v2/“构建Angular8项目,并将dist复制到/v2目录中

这个问题与第8条有关

我有一个在IIS上运行的网站,代码在.Net中,AngularJs 1.6说www.parent.com

我正在用纯Angular 8(单页应用程序)构建一个全新的网站,目前拥有www.parent.com项目的一些页面。我还必须在同一个域上运行它们。因此,我试图在虚拟目录中托管新网站

我尝试的是:

  • 创建了一个虚拟目录,比如说/v2
  • 使用
    ng build--base href”/v2--deploy url”/v2/“
    构建Angular8项目,并将dist复制到/v2目录中
  • 试图访问www.parent.com/v2/
  • 一切都很好,导航到不同的页面,等等。 例如,Angular8项目的路由工作正常-www.parent.com/v2/timelinewww.parent.com/v2/noticeboard

    但是,当我在子项目的一个页面上刷新页面时,它会出现以下错误

    HTTP Error 404.0 - Not Found
    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
    
    Most likely causes:
    The directory or file specified does not exist on the Web server.
    The URL contains a typographical error.
    A custom filter or module, such as URLScan, restricts access to the file.
    
    Things you can try:
    Create the content on the Web server.
    Review the browser URL.
    Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.
    
    Detailed Error Information:
    Module     IIS Web Core
    Notification       MapRequestHandler
    Handler    StaticFile
    Error Code     0x80070002
    Requested URL      http://parent.com:80/Child/timetable/worker
    Physical Path      D:\WebSites\Child\timetable\worker
    Logon Method       Anonymous
    Logon User     Anonymous
    
    更新:

  • 根据添加了web.config

  • 在angular 8项目的index.html中添加了

  • 目录结构:

    C:\web\Project\Parent->.net项目

    C:\web\v2\->angular8项目

    IIS中名为v2的虚拟目录指向C:\web\v2

    C:\web\v2\src\web.config

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
       <system.webServer>
          <directoryBrowse enabled="true" />
          <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="/v2" />
                </rule>
             </rules>
          </rewrite>
       </system.webServer>
    </configuration>
    
    
    
    是否在IIS中启用url重写扩展?如果您启用了url重写,我建议您可以发布详细信息配置设置供我们测试。我还没有对重写扩展做任何操作,将检查文档。你能给我指一些关于它的教程吗?@BrandoZhang我已经用配置更新了答案