Do I need to dispose an HttpResponseException from Request.CreateResponse()?

Viewed 2075

I have this code within a request handling method of an ApiController:

if (uri != null)
{
    HttpResponseMessage r = Request.CreateResponse(HttpStatusCode.Redirect);
    r.Headers.Location = uri;
    throw new HttpResponseException(r);
}

The potential problem is that "r" is never disposed (in my code at least).
I could wrap this in a using, but then wouldn't "r" get disposed before the response is streamed to the client?

What is the correct way to handle this?

2 Answers
Related