GetSeName method should
NEVER return an empty string as it is always required, otherwise the link will not work. I have changed the method to include
if (result == "")
{
result = ValidateSeName(entity, "", "", true);
urlRecordService.SaveSlug(entity, result, 0);
}
This way, if there is no SeName the entityId will be used instead.
The full method is now
public static string GetSeName<T>(this T entity, int languageId, bool returnDefaultValue = true,
bool ensureTwoPublishedLanguages = true)
where T : BaseEntity, ISlugSupported
{
if (entity == null)
throw new ArgumentNullException("entity");
string result = string.Empty;
string entityName = typeof(T).Name;
var urlRecordService = EngineContext.Current.Resolve<IUrlRecordService>();
if (languageId > 0)
{
//ensure that we have at least two published languages
bool loadLocalizedValue = true;
if (ensureTwoPublishedLanguages)
{
var lService = EngineContext.Current.Resolve<ILanguageService>();
var totalPublishedLanguages = lService.GetAllLanguages(false).Count;
loadLocalizedValue = totalPublishedLanguages >= 2;
}
//localized value
if (loadLocalizedValue)
{
result = urlRecordService.FindSlug(entity.Id, entityName, languageId);
}
}
//set default value if required
if (String.IsNullOrEmpty(result) && returnDefaultValue)
{
result = urlRecordService.FindSlug(entity.Id, entityName, 0);
}
if (result == "")
{
result = ValidateSeName(entity, "", "", true);
urlRecordService.SaveSlug(entity, result, 0);
}
result = HttpUtility.UrlEncode(result);
return result;
}