【发布时间】:2017-07-26 01:12:21
【问题描述】:
我们通过强制客户端通过我们的应用程序进行 CRUD 调用来限制对企业系统的访问,然后我们的应用程序会将相同的请求转发到其目的地,并保存标头信息。
- 客户端向
ApiController发出请求 - 我们将请求传递给服务层
- 服务层将请求转发到其预期的企业系统目的地。
详细说明以上几点:
客户端对此发出请求:
[HttpGet]
[Route("opportunities({id:guid})")]
[Route("opportunities")]
public async Task<HttpResponseMessage> GetOpportunity()
{
var query = Request.RequestUri.AbsolutePath.Split('/').Last() + Request.RequestUri.Query;
var response = await _opportunityService.GetOpportunity(query);
return response;
}
服务方法GetOpportunity定义为:
public async Task<HttpResponseMessage> GetOpportunity(string query)
{//at the line below is where i want to send the same headers that were passed in originally at step 1
var response = Client.Instance.GetAsync(Client.Instance.BaseAddress + query); //this is just using HttpClient to make this call
var responseType = response.Result.StatusCode;
if (responseType == HttpStatusCode.NotFound)
return new HttpResponseMessage
{
StatusCode = responseType
};
return await response;
}
我们如何保存第 1 步的标头信息?
通过使用以下中间件,我已经能够获取所有标题信息;但是,我不确定如何缓存它们或使它们可用于服务层:
public class HeaderAuthenticationAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
var headers = actionContext.Request.Headers;
}
}
【问题讨论】:
标签: c# asp.net .net asp.net-web-api visual-studio-2017