[英]IIS URL Rewrite for nested application
我在 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>
现在我将 Web API 应用程序作为子应用程序(嵌套应用程序)托管在 IIS 中,并将 React 应用程序作为父应用程序。 现在的问题是,当前端应用程序向 Web API 发出请求时,我得到403 - Forbidden: Access is denied.
我检查了父应用程序和子应用程序都未选中 Require SSL。 当我删除 web.config 中的重写规则时,一切正常,除了我无法刷新页面。 那么如何使用嵌套应用程序重写规则。 只是为了提供更多详细信息,我们使用的是 IIS 10,站点名称是 ReactApp 和 WebApiApp(子应用程序)。 该应用程序在 https 中运行。
我通过在 rewrite url <match url="^((?.childapp).)*$" />
中添加以下内容来修复它,其中 childapp 是嵌套应用程序的名称。 所以基本上说如果不是 Web API 调用然后使用规则,否则忽略后端 API 调用的规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.