【问题标题】:How to set up an IIS Rewrite rule for everything except the /api route如何为除 /api 路由之外的所有内容设置 IIS 重写规则
【发布时间】:2015-07-18 06:48:45
【问题描述】:

我正在设置一个带有角度前端的 webapi 应用程序。我想启用 html5mode,所以 Web 服务器需要有一个重写规则,将所有请求发送回索引页面。

问题是 /api 路由中的操作当然匹配此规则,所以我的 REST 调用都不会通过重写规则。

我确定我不是一个人遇到这个问题。任何人都可以分享 web.config 的部分,以便我的 REST 服务正常工作并且 html5mode 不会损坏吗?

【问题讨论】:

标签: asp.net-mvc angularjs iis-7


【解决方案1】:
  <system.webServer>
    <modules>
      <remove name="FormsAuthentication" />
    </modules>
    <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>
    <rewrite>
      <rules> 
        <rule name="Main Rule" 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}" matchType="Pattern" pattern="api/(.*)" negate="true" />

          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-26
  • 2020-12-13
  • 1970-01-01
  • 2013-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多