【问题标题】:How to redirect all call to another application with web api如何使用 web api 将所有调用重定向到另一个应用程序
【发布时间】:2016-10-01 01:49:51
【问题描述】:

我有一个带有 web api 控制器和 angular 客户端的 ASP.NET 应用程序。我用下一种方式调用web api:

this.$http.get('api/menu/get', {
                params: {}
            })

所以我调用像http://myApp/api/menu/get 这样的绝对路径。现在我应该从另一个 Web 应用程序中获取一些数据,例如:http://secondApp/reportsApi/reports/get

如何从 secondApp web api 获取数据? 据我所知,我可以从 UI 中调用绝对路径,例如

this.$http.get('http://secondApp/reportsApi/reports/get', {
                params: {}
            })

但这看起来不是一个好的决定。我不会打这样的电话:

this.$http.get('reportsApi/reports/get', {
                params: {}
            })

并以某种方式将此调用从“myApp”重定向到“secondApp”。

【问题讨论】:

  • 你为什么要做这个客户端?您应该在服务器中设置代理通行证。
  • 对不起,也许我在描述的地方有错误,但这正是我想做的,但我不知道怎么做。如何在服务器中设置代理传递以仅重定向诸如“reportsApi/reports/get”之类的调用?

标签: asp.net .net angularjs asp.net-mvc asp.net-web-api


【解决方案1】:

这描述了如何使用内置的 IIS 重写模块。
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

你最终会在你的 web.config 中得到类似的东西:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect Reports Api" stopProcessing="true">
        <match url="^reportsApi/reports/get" />
        <action type="Rewrite" url="http://secondApp/reportsApi/reports/get" />
      </rule>
    <rules>
  <rewrite>
<system.webServer>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 2022-06-26
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 2013-02-10
    相关资源
    最近更新 更多