I have an Asp.net Web API project which has several CRUD methods.
On top of these methods, i want to add an Authorization service that reads the Authorization
header and prevent users of accessing the resources (if they are not authorized).
// Method on internal IP Project
public class InternalController : ApiController
{
public void Create(CreateRequest request)
{
// implement the method
}
}
// Method on public IP Project
public class ExternalController : ApiController
{
public async Task Create(CreateRequest request)
{
// validate Authorization header and throw exception if not valid
using (HttpClient client = new HttpClient())
{
string parameters = string.Format("param1={0}¶m2={1}", request.Param1, request.Param2);
client.BaseAddress = new Uri("http://192.168.1.1/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/internal/create?" + parameters);
response.EnsureSuccessStatusCode();
}
}
}
Is there any way of "Redirecting" the request from the External API to the Internal API more easily?
Right now, i have to manually re-create all the parameters that i receive in ExternalAPI and send them in the InternalAPI, even if they are the same.
Can i make HttpClient
automatically send the HttpRequestMessage (Request)
object that i have in ExternalAPI method?
InternalController
andExternalController
on the same web project? – haim770 Apr 30 at 9:18