I want to allow forward slash into SENAME of my nop project. How can i do this using customisation?
for example,
- I want product url like "/product/htc-one-m8-android-l-50-lollipop" instead of "/htc-one-m8-android-l-50-lollipop"
- I want category url like "/category/desktops" instead of "/desktops"
I am using nopcommerce 4.3 version.
sample code
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>("SeName}");
I am not getting call into this TransformAsync method. i want to get call here when i add "/product/sename" into url
public override ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
{
}
You can register routes for
Product/andCategory/path inGenericUrlRouteProviderlike:If you want your existing links to be displayed correctly your also want to update default
ProductandCategoryroutes and your register routes method should look like:Update:
In order to allow
/in product name, there are multiple changes you need to make.Allow / in sename, to do that
UrlRecordServicehasGetSeNamemethod and inokCharsvariable you want to add/as one of the valid characters.Fix your call related to dynamic routes. You have
{missing in your code. It should be:endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>("{SeName}");Update
SlugRouteTransformer'sTransformAsyncmethod to unescape URL before searching for matching Url records using:var urlRecord = _urlRecordService.GetBySlug(Uri.UnescapeDataString(slug));I believe that is all and after that you should be able to allow
/in your entity name. Be aware that this might break existing pages and links might not work perfectly all the time. Also, if you look closely, your product/category url will have%2Fin the URL, if you want to change that you will have to unesacpe all the links before rendering, something like:<a href="@System.Uri.UnescapeDataString(Url.RouteUrl("Product", new {SeName = Model.SeName}))">@Model.Name</a>BUT IT WILL BREAK A LOT OF THINGS!