6.41HttpContext Forwarding Extension Methods

Created on Aug 17, 2026~1 min read

The framework provides various extension methods for HttpContext to meet the HTTP request forwarding needs of various scenarios.

cs
// Returns an HttpResponseMessage objecthttpContext.Forward(requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationhttpContext.Forward(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsync(requestUri, configure, completionOption, forwardOptions);    // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns HttpRemoteResult<T>httpContext.Forward<T>(requestUri, configure, completionOption, forwardOptions);    // Automatically obtains HttpContext.Request.Method for configurationhttpContext.Forward<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsync<T>(requestUri, configure, completionOption, forwardOptions); // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsync<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns the target type ThttpContext.ForwardAs<T>(requestUri, configure, completionOption, forwardOptions);  // Automatically obtains HttpContext.Request.Method for configurationhttpContext.ForwardAs<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsAsync<T>(requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsAsync<T>(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns a string typehttpContext.ForwardAsString(requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationhttpContext.ForwardAsString(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsStringAsync(requestUri, configure, completionOption, forwardOptions);    // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsStringAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns a byte array typehttpContext.ForwardAsByteArray(requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationhttpContext.ForwardAsByteArray(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsByteArrayAsync(requestUri, configure, completionOption, forwardOptions);    // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsByteArrayAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns a Stream typehttpContext.ForwardAsStream(requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationhttpContext.ForwardAsStream(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsStreamAsync(requestUri, configure, completionOption, forwardOptions);    // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsStreamAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns an IActionResult typehttpContext.ForwardAsResult(requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationhttpContext.ForwardAsResult(httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsResultAsync(requestUri, configure, completionOption, forwardOptions);    // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsResultAsync(httpMethod, requestUri, configure, completionOption, forwardOptions);// Returns an object typehttpContext.ForwardAs(resultType, requestUri, configure, completionOption, forwardOptions);  // Automatically obtains HttpContext.Request.Method for configurationhttpContext.ForwardAs(resultType, httpMethod, requestUri, configure, completionOption, forwardOptions);await httpContext.ForwardAsAsync(resultType, requestUri, configure, completionOption, forwardOptions);   // Automatically obtains HttpContext.Request.Method for configurationawait httpContext.ForwardAsAsync(resultType, httpMethod, requestUri, configure, completionOption, forwardOptions);