简体   繁体   English

IIS URL 重写嵌套应用程序

[英]IIS URL Rewrite for nested application

I have SPA developed in React and back-end as ASP.NET Web API.我在 React 和后端开发的 SPA 为 ASP.NET Web API。 The React application is hosted in IIS and have a rewrite URL so if the page is refreshed the page stays. React 应用程序托管在 IIS 中,并重写了 URL,因此如果页面被刷新,页面将保留。 The URL rewrite looks like 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>

Now I hosted Web API application as a child application (nested application) in IIS with React application as parent.现在我将 Web API 应用程序作为子应用程序(嵌套应用程序)托管在 IIS 中,并将 React 应用程序作为父应用程序。 Now the issue is when the front-end application makes a request to Web API I get 403 - Forbidden: Access is denied.现在的问题是,当前端应用程序向 Web API 发出请求时,我得到403 - Forbidden: Access is denied. I checked and both the parent and child applications have Require SSL unchecked.我检查了父应用程序和子应用程序都未选中 Require SSL。 When I removed the rewrite rule in web.config everything is working except I cannot refresh the page.当我删除 web.config 中的重写规则时,一切正常,除了我无法刷新页面。 So how to have rewrite rule with the nested application.那么如何使用嵌套应用程序重写规则。 Just to provide more details, we are using IIS 10 and name of the site is ReactApp and WebApiApp (child application).只是为了提供更多详细信息,我们使用的是 IIS 10,站点名称是 ReactApp 和 WebApiApp(子应用程序)。 The application runs in https.该应用程序在 https 中运行。

I fixed it by adding the following in rewrite url <match url="^((?.childapp).)*$" /> where childapp is the name of the nested application.我通过在 rewrite url <match url="^((?.childapp).)*$" />中添加以下内容来修复它,其中 childapp 是嵌套应用程序的名称。 So basically saying that if it is not Web API call then use the rule otherwise ignore the rule for the back-end API calls.所以基本上说如果不是 Web API 调用然后使用规则,否则忽略后端 API 调用的规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM