-
Hi, i am using Direct Forward Pattern. I need the underlying code to be executed even when the request is forwarded. I tried doing this by calling next(); after the request is forwarded but i am getting a System.InvalidOperationException in System.Private.CoreLib.dll error. Status Code cannot be set because response has already started. app.Use((context, next) =>
{
if (conditionIsMet)
{
var error = await forwarder.SendAsync(httpContext, endpoint), httpClient, requestOptions, transformer);
// Check if the proxy operation was successful
if (error != ForwarderError.None)
{
var errorFeature = httpContext.Features.Get<IForwarderErrorFeature>();
var exception = errorFeature.Exception;
}
await next(); <-- i am still trying to call the underlying service but return result of forwarded request
}
else
{
await next();
}
});
app.UseEndpoints(...) I tried instantiating a new thread and calling next() in there but i am getting the same error. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You shouldn't call next after forwarding, the response has already been sent. What other code are you trying to execute? |
Beta Was this translation helpful? Give feedback.
You shouldn't call next after forwarding, the response has already been sent. What other code are you trying to execute?