如何设置 uri 重写以读取特定 url 或文件?

How set uri rewrite to read specific url or file?

我对如何使用 uri 重写有点困惑。我有一个项目,其中包括 c# web api 2 和 angular,我想从 web api 获取数据。所以我在 web.config 中使用了它:

<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="./index.html" />
    </rule>
      </rules>
    </rewrite>
  <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

我希望通过键入 http://localhost/ 打开 index.html。但是我得到 HTTP 404 找不到资源。 但是当我输入 http://localhost/index.html 时,我的程序开始工作没有任何问题。我想知道如何通过输入 http://localhost/ 来实现这一点

经过研究,我找到了获取 .html 类型文件的方法,因此我将 web.config 文件更改为:

<compilation debug="true" targetFramework="4.7.2">
      <buildProviders >
        <add extension=".htm" type="System.Web.Compilation.PageBuildProvider"  />
        <add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
      </buildProviders>   
 </compilation>

然后我的应用程序运行良好。