1

I'm having an issue figuring out why calling

Response.Redirect(urlWithQueryParams, false)

where urlWithQueryParams is "localhost/forms/confirmation?form=%7BE92EB767-8BB6-44F1-A4C9-9CDB2C2DBCCC%7D&id=8454DDBC072C49A48AD116019A9D5824&value=gESO%2BDDBGEAA7eZMz2JqHQ%3D%3D" is dropping all query params that are part of the url when the redirect happens. I currently have the redirect setup as

Response.Redirect(urlWithQueryParams);

however, calling like that is causing a ThreadAbortAbortException to be thrown whenever the user submits the form and redirect is triggered. I've found a couple a SO posts saying to add the false flag on there and follow that with

HttpContext.Current.ApplicationInstance.CompleteRequest();

But whenever I add the false flag, the page redirects to the proper page but drops the query params along the way. The confirmation page that the user is redirected to needs to those params in order to be displayed properly and I can't find anything that points to a cause for this issue. Has anyone else ever faced this issue?

themillennialdev
  • 43
  • 1
  • 1
  • 6

1 Answers1

0

This is the way that I do it.

try
{
    // this is throw the ThreadAbortException exception
    Response.Redirect(stringUrl, true);
}
catch (ThreadAbortException)
{
    // ignore it because we know that comes from the redirect
}
catch (Exception x)
{
    // log the error
}

I explain here why Redirect to a page with endResponse to true VS CompleteRequest and security thread

In short, the exception is normal because you stop the processing of the page, and we want to do that for two reasons. 1) for security, 2) for just stop the rest of cpu processing that is no needed.

Also it's strange why you lose your query string because the endResponse is only "ends" the processing calling AbortCurrentThread(); - probably some code on the rest of the thread is add something...

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Two negative votes on both answers, at least tells why and what is the issue if you abort a thread. Also check the security issue when you do not stop the thread. A thread that runs the page must be stopped - why is that bad ? And the thread is stopped only with exception... – Aristos Aug 22 '17 at 19:58
  • if you really understand the answer here you see that if you do not stop the processing you have security issue ... https://stackoverflow.com/questions/14641143/redirect-to-a-page-with-endresponse-to-true-vs-completerequest-and-security-thre/14641145#14641145 – Aristos Aug 22 '17 at 20:03