using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Web;
using Umbraco.Web.Routing;
namespace MyWebsite.Core.UrlProviders
{
public class FrontpageUrlProviderApplicationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, FrontpageUrlProvider>();
}
}
public class FrontpageUrlProvider : IUrlProvider
{
public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
var content = umbracoContext.ContentCache.GetById(id);
if (content != null && content.AncestorOrSelf(1).HasValue("umbracoInternalRedirectId") && content.AncestorOrSelf(1).GetProperty("umbracoInternalRedirectId").DataValue.ToString() == content.Id.ToString())
{
return content.AncestorOrSelf(1).Url;
}
return null;
}
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
return Enumerable.Empty<string>();
}
}
}