Here is the relevant section of code at the end of the Page_Load event:
Code:
if (AppLogic.AppConfig("AddToCartAction").ToUpperInvariant() == "STAY" && ReturnURL.Length != 0)
{
Response.Redirect(ReturnURL);
}
else
{
if (ReturnURL.Length == 0)
{
ReturnURL = String.Empty;
if (Request.UrlReferrer != null)
{
ReturnURL = Request.UrlReferrer.AbsoluteUri; // could be null
}
if (ReturnURL == null)
{
ReturnURL = String.Empty;
}
}
if (CartType == CartTypeEnum.WishCart)
{
Response.Redirect("wishlist.aspx?ReturnUrl=" + Security.UrlEncode(ReturnURL));
}
if (CartType == CartTypeEnum.GiftRegistryCart)
{
Response.Redirect("giftregistry.aspx?ReturnUrl=" + Security.UrlEncode(ReturnURL));
}
Response.Redirect("ShoppingCart.aspx?add=true&ReturnUrl=" + Security.UrlEncode(ReturnURL));
}
In the line marked in Orange, there are two conditions that could cause the check to fail:
1. AddToCartAction is not set to 'STAY' OR
2. No ReturnUrl was specified in the querystring
In the "else" branch, the original code performed the same steps regardless of the reason for falling through to this branch. I have added the ReturnURL.Length==0 (in red) check so that it mimics condition #2. Essentially, if the user supplied a return URL then we don't want to reset it in the "else" branch.