So i have written this beautiful piece of code this were supuse to send all requests with a json prefix to our Json action in the product controller insted of the normal product action/view.
public class RoutingServiceDecorator : RoutingService
........
public override bool TryGet([NotNull] AssortmentRouteLookupInfo lookupInfo, out RouteInfo routeInfo)
{
//When we get request to litium we inject our magic
bool result = false;
if (lookupInfo.Segments.Length > 1 && lookupInfo.Segments[0] == "json")
{
//Remove the json slug from the request
var defaultSegments = lookupInfo.Segments.Slice(1);
//lookupInfo is read only, so we need to recreate it to alter the url segments
lookupInfo = new AssortmentRouteLookupInfo(
lookupInfo.CultureInfo,
defaultSegments,
lookupInfo.WebsiteSystemId,
lookupInfo.AssortmentSystemId,
lookupInfo.ChannelSystemId,
lookupInfo.UseHistory,
lookupInfo.DisplayOnWebsiteSystemId);
//Make a lookup on the base url
result = _parent.TryGet(lookupInfo, out routeInfo);
//If we have a hit we replace the controller action
if (result)
{
// eg: "~/MVC:Litium.Accelerator.Mvc.Controllers.Product.ProductController, Litium.Accelerator.Mvc:ProductWithVariants";
var templateParts = routeInfo.TemplateFileName.Split(',');
//Make sure we have a default controller action selected
if (templateParts.Length > 1)
{
var controller = templateParts[0].Trim(); // eg: "~/MVC:Litium.Accelerator.Mvc.Controllers.Product.ProductController
var action = templateParts[1].Trim(); // eg: Litium.Accelerator.Mvc:ProductWithVariants
//Replace the template action to use the injected one
routeInfo.TemplateFileName = routeInfo.TemplateFileName.Replace(action, "Litium.Accelerator.Mvc:Json");
}
}
return result;
}
else
{
//Do the normal lookup
return _parent.TryGet(lookupInfo, out routeInfo);
}
}
This whould work like magic, BUT what happens, is that before we reach the Json action in the product controller, litium looks up the real url, and do a 301 redireckt to so we always end up in the โrealโ action.
Can I somehow disable this redirect from code? or must i just call the product controller directly from here?
Litium version: 7.4