Cannot redirect after HTTP headers have been sent.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I am getting this error: Cannot redirect after HTTP headers have been sent.

This is happening when I hit the "confirm" button in the last step of the One Page Checkout. It tries to find PayPal to let the user pay and it is giving me an error about how Paypal.com couldn't be found because of a DNS issue.  I looked in my log and I see whenever this happens, the above error (Cannot redirect after HTTP headers have been sent) shows up.  How can I fix this?
12 years ago
I will include the stack trace and other information  as well.

Page URL:   http://wishesfromhome.com/checkout/opccompleteredirectionpayment

Referrer URL:   http://wishesfromhome.com/onepagecheckout

System.Web.HttpException (0x80004005): Cannot redirect after HTTP headers have been sent. at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) at System.Web.HttpResponseWrapper.Redirect(String url, Boolean endResponse) at System.Web.Mvc.RedirectToRouteResult.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) at System.Web.Mvc.Controller.ExecuteCore() at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d() at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
12 years ago
Did you get a solution to this? I am having the same problem?

S
12 years ago
https://www.nopcommerce.com/boards/t/15460/error-with-card-save-plugin.aspx
12 years ago
I too have started getting the 'Cannot redirect after HTTP headers have been sent.' error when redirecting to my payment provider.

I am unsure what I am meant to do, I have looked through the link Andrei posted above, have enabled errors but just get a white screen whilst on... http://www.sitename.com/checkout/OpcCompleteRedirectionPayment

What am I missing?

I think I started getting this on my local host version of 2.30 all of a sudden, and now still getting it on 2.40
12 years ago
ok... I've applied the code that Andrei referenced as his fix... however, I am failing through this else...

else
                {
                    //if·no·redirection·has·been·done·(to·a·third-party·payment·page)
                    //theoretically·it's·not·possible
                    return RedirectToRoute("CheckoutCompleted");
                }

I must have something wrong with my Payment plugin. I will look at that next.
12 years ago
After searching around it appears if I turn off compression I no longer get the white screen and everything works...

commonsettings.enablehttpcompression = false

Anyone got an opinion on this?
12 years ago
This issue is fixed in the upcoming version 2.5. See changeset 24aab2bc459e
12 years ago
Ok fair enough... I thought I had copied the fix from codeplex to my version of the checkout controller but still white screened.

src/Presentation/Nop.Web/Controllers/CheckoutController.cs (view diff)

Maybe I need to apply the other fixes too.
12 years ago
Hi, I'm getting the same error. When I try and checkout using the PayPoint plugin, I get a blank page and an error in my Log table:

"Cannot redirect after HTTP headers have been sent."

Stepping through the code, it falls through OpcCompleteRedirectionPayment action within the CheckoutController.

This then gets down to _paymentService.PostProcessPayment(postProcessPaymentRequest);

This falls through to the PostProcessPayment method within the PayPointPaymentProcessor.cs file which builds a RemotePost and is meant to POST away to PayPoint.

Stepping through the RemotePost.Post() method, it builds up the HTML form and ends with a _httpContext.Response.End() however, it is then continuing back to the CheckoutController and doing the 2.50 fix:

if (this.Response.IsRequestBeingRedirected)
{
    //redirection has been done in PostProcessPayment
    return Content("Redirected");
}
else
{
    //if no redirection has been done (to a third-party payment page)
    //theoretically it's not possible
    return RedirectToRoute("CheckoutCompleted");
}


However, this.Response.IsRequestBeingRedirected is false so it's falling through the RedirectToRoute, causing the Log error.

Shouldn't it not even reach that point? It doesn't appear to be doing the POST at all.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.