Monday, May 30, 2016

IHttpHandler response redirect shows Object moved to here

While working on a HTTP Handler for PDF files, I found that redirecting to a new URL would display:
Object moved to here.
 This was using the following code:

context.Response.Redirect(pdfUrl, false);
context.Response.StatusCode = 301;
context.Response.End();

This could have been related to the redirect begin inside a try catch block, so the following code works better by flushing a redirect header.

HttpResponse Response = HttpContext.Current.Response;
Response.StatusCode = 301;
Response.StatusDescription = "Moved Permanently";
Response.RedirectLocation = pdfUrl;
Response.Flush();

This then worked as expected.

No comments:

Post a Comment