AI OnAI Off
So, I think I may have done this. It seems to work anyway. I'd be interested in comments -- did I do this right?
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using EPiServer.Configuration;
using EPiServer.Globalization;
using EPiServer.Core;
namespace EPiServer
{
public class ShortUrlRewriteProvider : EPiServer.Web.FriendlyUrlRewriteProvider
{
protected override bool ConvertToExternalInternal(UrlBuilder url, object internalObject, System.Text.Encoding toEncoding)
{
var pageRef = internalObject as PageReference;
if (pageRef == null || pageRef == PageReference.EmptyReference)
{
return base.ConvertToInternalInternal(url, ref internalObject);
}
// Get the page
var pageData = DataFactory.Instance.GetPage(pageRef);
// Does this page have a simple address?
if (pageData.Property["PageExternalURL"] != null && pageData.Property["PageExternalURL"].Value != null)
{
// "Reset" the path to be nothing but the raw site URL (so, essentially just the protocol and the domain)
url.Uri = Settings.Instance.SiteUrl;
// Now set the path to be just the simple URL
url.Path = String.Concat("/", pageData.Property["PageExternalURL"].Value.ToString());
return true;
}
// No simple address, just handle normally
return base.ConvertToExternalInternal(url, internalObject, toEncoding);
}
}
}
Is it possible to get CMS 6 to use the short URL for a page everywhere that page is linked? My client has some legacy SEO they're bringing over, and they want Drupal-esque funtionality -- they want to set the short URL for a page and for that become the "URL of record" which is used in all navigation to that page.
Possible? I know I could roll my own nav controls, but I was wondering if I could override something in the URL rewriter instead to make this behavior more core.