0
  • We have a private server that I cannot access.

  • We have another public server that I can access.

  • The public server can access the private server. (ie. A proxy server)

So I want to build an ASP.Net framework app on the public server that will simply forward all query parameters, body, headers, everything, to the private server.

When I make a route, how can I just forward everything to the private server's URL?

I have this so far but not sure if I'm thinking about this the right way. I feel like there's a way that is more automated:

[System.Web.Mvc.Route("search")]
public object Search()
{
    var request = HttpContext.Current.Request;
    var BaseUrl = "http://my-private-server-url";
    var client = new RestClient(BaseUrl);
    var newRequest = new RestRequest(request.HttpMethod);

    // The code below errors:
    // Cannot convert from
    // 'System.Collections.Specialized.NameValueCollection' to
    // 'System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, string>>'
    newRequest.AddHeaders(request.Headers);

    // How do I forward the request body too?

    var response = client.Execute(newRequest);
    return response.Content;
}
AskYous
  • 3,219
  • 4
  • 35
  • 59
  • Does this answer your question? [How to create a simple proxy in C#?](https://stackoverflow.com/questions/226784/how-to-create-a-simple-proxy-in-c) – JuanR Mar 15 '21 at 23:16

0 Answers0