Temporary redirect from product page

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

Check the response status code for the request that ends up into the redirect response. This only to ensure that the response ends up in a redirect (302) instead of a permanent redirect (301).

We get a 301, but i expect a 302. We’re using RedirectTemporary on the RouteRequestInfo result.

In Litium 8 you need to use the IUrlRedirectResolver instead of the IPageNotFoundResolver to get a redirect like this to work. If that is not working, please create a bug on the docs site with steps for reproduction.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.