This post talks about writing a simple HTTP proxy logic in C# or ASP.NET Core. And allowing your project to proxy the request to any other URL. It is not about deploying a proxy server for your ASP.NET Core project.

Before starting, you need to be clear about the target you are going to proxy for. It shall be an URL.

Add the following code anywhere of your project.

This method covert user sends HttpContext.Request to a reusable HttpRequestMessage. So you can send this message to the target server.

After your target server response, you need to copy the responded HttpResponseMessage to the HttpContext.Response so the user’s browser just gets it.

And now the preparation is complete. Back to our controller:

And try to access it. It will be proxied to google.com

Leave a comment

Your email address will not be published.