The constraint reference 'slugify' could not be resolved to a type

浪尽此生 提交于 2019-12-06 11:17:34

As ASP.NET Core Documentation says I have to configure Parameter transformer using ConstraintMap. So I have done as follows and it works:

Routing configuration in the ConfigureServices method should be as follows:

services.AddRouting(option =>
            {
                option.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer);
                option.LowercaseUrls = true;
            });

Then the SlugifyParameterTransformer as follows:

public class SlugifyParameterTransformer : IOutboundParameterTransformer
    {
        public string TransformOutbound(object value)
        {
            // Slugify value
            return value == null ? null : Regex.Replace(value.ToString(), "([a-z])([A-Z])", "$1-$2").ToLower();
        }
    }

Thank you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!