You can use Action Filter. For 4.1
Create a Custom Action Filter:
public class CustomActionFilter : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
var actionName = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor).ActionName;
var controllerName = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor).ControllerName;
if (!string.IsNullOrEmpty(controllerName) && !string.IsNullOrEmpty(actionName) && context.Controller is Web.Controllers.ProductController)
{
switch (controllerName)
{
case "Product":
context.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "CustomProduct", action = "ProductDetails", productId = context.ActionArguments["productId"] }));
break;
}
}
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}
Add your action filter to CustomStartup : INopStartup
services.AddMvc(options =>
{
//an instant
options.Filters.Add(new CustomActionFilter());
//By the type
options.Filters.Add(typeof(CustomActionFilter));
});
Then Add Route Request in CustomGenericPathRoute : GenericPathRoute
case "customproduct":
currentRouteData.Values["controller"] = "CustomProduct";
currentRouteData.Values["action"] = "ProductDetails";
currentRouteData.Values["productid"] = urlRecord.EntityId;
currentRouteData.Values["SeName"] = urlRecord.Slug;
break;
Then register your route in CustomGenericUrlRouteProvider : IRouteProvider
//Product
routeBuilder.CustomMapGenericPathRoute("Plugin.Misc.YourPlugin.ProductDetails", "{GenericSeName}",
new { controller = "CustomProduct", action = "ProductDetails" });
make sure in your CustomGenericUrlRouteProvider
public int Order
{
get { return int.MaxValue; }
}
Otherwise url will be without slug.