Im having some issues with temporary redirects. the idea is that when a product becomes out-of-stock all variants shall be unpublished, and a temporary redirect to the products main category is created. However, when the product becomes back-in-stock and re-published the redirect is still cached by the browser. Any ideas on how to overcome this? This is the code used in the PageNotFoundResolverDecorator:
var result = new RouteRequestInfo();
var rawUrl = routeRequestLookupInfo.RawUrl.ToLower();
var url = routeRequestLookupInfo.Path.ToLower().Replace(".html", "");
var productUrl = routeRequestLookupInfo.Path.Split('/').LastOrDefault();
var cultureInfo = _languageService.Get(routeRequestLookupInfo.Channel.WebsiteLanguageSystemId.GetValueOrDefault()).CultureInfo;
var channelSystemId = routeRequestLookupInfo.Channel.SystemId;
BaseProduct baseProduct = null;
var systemId = Guid.Empty;
if (_routingHelperService.TryGetBaseProduct(productUrl, cultureInfo, out systemId))
{
baseProduct = _baseProductService.Get(systemId);
}
if (baseProduct == null && _routingHelperService.TryGetVariant(productUrl, cultureInfo, out systemId))
{
var variant = _variantService.Get(systemId);
baseProduct = _baseProductService.Get(variant.BaseProductSystemId);
}
if (baseProduct == null && _routingHelperService.TryGetProductHistoryUrl(cultureInfo, channelSystemId, productUrl, out systemId, out bool isVariant))
{
if (isVariant)
{
var variant = _variantService.Get(systemId);
baseProduct = _baseProductService.Get(variant.BaseProductSystemId);
}
else
{
baseProduct = _baseProductService.Get(systemId);
}
}
if (baseProduct != null)
{
var categories = _categoryService.GetByBaseProduct(baseProduct.SystemId);
var mainCategory = categories.FirstOrDefault(c => c.ProductLinks.Any(l => l.BaseProductSystemId == baseProduct.SystemId && l.MainCategory == true));
var mainCategoryUrl = _urlService.GetUrl(mainCategory, new CategoryUrlArgs(channelSystemId) { AbsoluteUrl = false });
if (baseProduct.Fields.GetValue<bool>(ProductFieldNameConstants.AllowNotifyMe) == false)
{
result.RedirectTemporary = mainCategoryUrl;
routeRequestInfo = result;
HttpContext.Current.Response.Headers["Cache-Control"] = "no-cache";
return true;
}
}
Am i doing this in the wrong place?
Litium version: 7.7.9