且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Asp.net网页API重定向请求

更新时间:2022-12-09 11:28:11

当谈到的ASP.NET Web API 。 HttpClient的不会自动跳转。当你已经成为从内部服务的响应可以将其传递给外部。或者,你可以重定向你的动作如这里

When speaking about ASP.NET Web API. HttpClient will not automatically redirect you. When you have become response from internal service you can pass it to external. Or you can redirect your action like here

要使它正确重定向客户端从视图使用HTTP重定向页眉和repsonse codeS的REST点。例如 HTTP响应code 302 。然后,客户端应该能够在这样的反应code发生反应,并从Location头重定向地址。但是,它是关于重定向客户端。

To make it correct redirection for client from REST point of view use HTTP Redirect Headers and repsonse codes. For example HTTP response code 302. And then client should be able to react on such response code and get redirect address from Location header. But it's about redirect for client.

当您的API从建筑谈论内部的一些业务的呼叫即可。您有以下选择:

When speaking about call of some internal services from your API from architecture. You have following alternatives:


  1. 呼叫您的内部服务作为类方法

  2. 请服务,服务电话

  3. Setup消息队列或公交车,你的API将通过服务总线与它通信。

拨打您的内部服务作为类方法
好简单。没有影响,延误服务调用。但你应该参考组装和它并不总是可能的。或者,这样的方式可能是不可能的,因为要求

Call your internal service as class method Very easy. No impact and delays for service call. But you should reference assembly and it's not always possible. Or such way could be not possible due to requirements

制作服务,服务电话
也有缺点:你的服务是紧密耦合的,你有延迟,应等待来自内部的服务响应。它认为是不好的做法。但可能是一个很好的解决方案,暂时作为第一步,服务总线。

Make service to service call Has disadvantages: your services are tightly coupled, you have delay and should wait for response from internal service. It's considered as bad practice. But could be a good temporarily solution as first step to service bus.

Setup消息队列或公交车,你的API将通过服务总线与它通信。
你的服务是分离的,独立的。你不应该等待回应。但它在技术上难以建立,使你的架构和基础设施更加复杂/

Setup message queue or bus and your API will communicate with it through service bus. Your services are decoupled and independent. You shouldn't wait for response. But it's technically harder to set up and make your architecture and infrastructure more complex/

由于摘要
没有***的方式从包装盒为你的架构,你应该从替代品根据自己的需要进行选择。

As summary There is no best way from the box for your architecture and you should select from alternatives based on your requirements.