【发布时间】:2021-06-06 23:44:39
【问题描述】:
我在 React 中开发了 SPA,并将后端作为 ASP.NET Web API。 React 应用程序托管在 IIS 中,并具有重写 URL,因此如果页面被刷新,页面将保留。 URL 重写看起来像
<rules>
<rule name="ReactJS Routes" 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>
现在我在 IIS 中将 Web API 应用程序作为子应用程序(嵌套应用程序)托管,并将 React 应用程序作为父应用程序。现在的问题是当前端应用程序向 Web API 发出请求时,我得到 403 - Forbidden: Access is denied.
我检查了父应用程序和子应用程序都未选中需要 SSL。当我删除 web.config 中的重写规则时,一切正常,除了我无法刷新页面。那么如何使用嵌套应用程序重写规则。只是为了提供更多详细信息,我们使用的是 IIS 10,站点名称是 ReactApp 和 WebApiApp(子应用程序)。该应用程序在 https 中运行。
【问题讨论】:
-
403 错误与 URL Rewrite 无关。可能是权限问题。可以使用FRT查看详细的错误日志:docs.microsoft.com/en-us/iis/troubleshoot/…
-
你是对的,我确实启用了日志记录,但没有看到错误。问题似乎是它们位于不同的应用程序池中,但现在当 UI 调用 Web API 时,看起来我只是获取父应用程序的 index.html 作为响应。
标签: reactjs url iis asp.net-web-api url-rewriting