// redirect if config says there's a switcheroo protected bool GetRedirectFromConfig(long categoryId, ref ActionResult redirectResult) { var catRed = CategoryRedirectConfig.GetCategoryRedirect(categoryId); if (catRed != null) { switch (catRed.ToWhat) { case CategoryRedirectToWhat.CategoryId: if (catRed.Value != categoryId.ToString(CultureInfo.InvariantCulture)) // don't do infinite redirect loop infinite redirect loop infinite redirect loop infinite redirect ... { redirectResult = RedirectPermanent( this.AssureHttpUrl(LinkGenerator.GenerateCategoryLink(long.Parse(catRed.Value)))); return(true); } break; case CategoryRedirectToWhat.ProductId: long pid; redirectResult = RedirectPermanent(this.AssureHttpUrl(LinkGenerator.GenerateProductLink(long.TryParse(catRed.Value, out pid) ? pid : (long?)null))); return(true); case CategoryRedirectToWhat.Path: // gen url based on store link minus last segment for store itself var storeLink = _linkGenerator.GenerateStoreLink(); if (!string.IsNullOrEmpty(storeLink)) { var lastSlashIdx = storeLink.LastIndexOf('/'); if (lastSlashIdx >= 0) { var redirectUrl = storeLink.Substring(0, lastSlashIdx); if (!catRed.Value.StartsWith("/")) { redirectUrl += "/"; } redirectUrl += catRed.Value; redirectResult = RedirectPermanent(this.AssureHttpUrl(redirectUrl)); return(true); } } break; } } return(false); }
// virtual for testing protected virtual CategoryRedirect GetCategoryRedirect(long categoryId) { return(CategoryRedirectConfig.GetCategoryRedirect(categoryId)); }