mardi 22 août 2017

Redirect.Response() is dropping query strings

Alright, so I've been struggling with this issue for a couple of hours now and I cannot for the life of me find out what is wrong here. I currently have a webform where after a user submits, I want to redirect them to the confirmation page. I'm building out the url like so:

var stringUrl = url + String.Format("?form={0}&id={1}&value={2}&fireAnalytics=true",
                                WebUtility.UrlEncode(formItem.ID.ToString()),
                                WebUtility.UrlEncode(ID.Parse(transactionId.FieldID).ToShortID().ToString()),
                                WebUtility.UrlEncode(CryptoUtil.Encrypt(transactionId.Value)));

This works perfectly well when I call response redirect like this:

HttpContext.Current.Response.Redirect(stringUrl);

When I call the redirect like that, everything works fine and the user is redirected to the confirmation page which pulls out data from the query strings just fine. All is good when doing this. However, with this current method, I'm seeing this error in the logs every time a user submits a form:

Exception: System.Threading.ThreadAbortException
Message: Thread was being aborted.
Source: mscorlib
   at System.Threading.Thread.AbortInternal()
   at System.Threading.Thread.Abort(Object stateInfo)
   at System.Web.HttpResponse.AbortCurrentThread()
   at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) 
at WEB.Cms.Sc.Forms.SaveActions.Redirect.Execute(ID formid, 
AdaptedResultList fields, ActionCallContext actionContext, Object[] data) in 
c:\devrepo\web.cms\web.Cms.Sc\Forms\SaveActions\Redirect.cs:line 78
at Sitecore.Forms.Core.Dependencies.DefaultImplActionExecutor.ExecuteSaving(ID 
formID, ControlResult[] fields, IActionDefinition[] actionDefinitions, 
Boolean simpleAdapt, ID sessionID)

So in order to get rid of this error, I came across this Stackoverflow post as well as this blogpost. The answer I got from those posts was clear, straightforward and made sense. However, the moment I add that second parameter as false:

HttpContext.Current.Response.Redirect(stringUrl, false);

The page still redirects, the error no longer appears in the logs, but it drops the query strings when doing so, which are needed for the confirmation page to be displayed properly. I'm kind of baffled as to why this is happening and I haven't found anything online that has given a solution. I've considered just dropping that data in session variables but this won't work since the business wants users to be able to bookmark confirmation pages in order to view them at a later time.

So yeah... I'm not sure what is going on here and I'd deeply appreciate any help or pointers. Thanks guys!

PS: Yes, I have also tried and it still didn't work :(

HttpContext.Current.Response.Redirect(stringUrl, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();




Aucun commentaire:

Enregistrer un commentaire