However, looking at EpiServer, I thught that I might re-write a PageData extension method which I wrote previously which generates the external URL of a page:
public static string GetExternalUrl(this PageData page)
{
string result = String.Empty;
if (page != null)
{
UrlBuilder builder = new UrlBuilder(page.LinkURL);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(builder, page, Encoding.UTF8);
result = builder.ToString();
}
return result;
}
This might have worked, but was still a bit of a kludge, so I turned to the undocumented waters of the EPiServer.Web.FriendlyUrlRewriteProvider
The FriendlyUrlRewriteProvider has a virtual method called:
ConvertToExternalInternal(EPiServer.UrlBuilder url, object internalObject, Encoding toEncoding)
Which is called by the EPiServer.Global.UrlRewriteProvider.ConvertToExternal(...) method I use in the Extension method above. Overriding that mehtod and converting the UrlBuilder's path property to lowercase seemed to do the trick.
Here's the final class:
public class LowerCaseUrlRewriteProvider : EPiServer.Web.FriendlyUrlRewriteProvider
{
public LowerCaseUrlRewriteProvider()
: base()
{
}
protected override bool ConvertToExternalInternal
(EPiServer.UrlBuilder url, object internalObject, Encoding toEncoding)
{
base.ConvertToExternalInternal(url, internalObject, toEncoding);
url.Path = url.Path.ToLower();
return true;
}
}
Update: Setting it up in the Web.Config
You now need to add this to the
<urlRewrite defaultProvider="LowerCaseUrlRewriteProvider">
<providers>
<add name="LowerCaseUrlRewriteProvider" type="Shared.EpiServer.Web.LowerCaseUrlRewriteProvider,Shared.EpiServer" />
<add name="EPiServerFriendlyUrlRewriteProvider" type="EPiServer.Web.FriendlyUrlRewriteProvider,EPiServer" />
<add description="EPiServer identity URL rewriter" name="EPiServerIdentityUrlRewriteProvider"
type="EPiServer.Web.IdentityUrlRewriteProvider,EPiServer" />
<add description="EPiServer bypass URL rewriter" name="EPiServerNullUrlRewriteProvider"
type="EPiServer.Web.NullUrlRewriteProvider,EPiServer" />
</providers>
</urlRewrite>
2 comments:
I've been using this provider for a while now and just fixed a bug with embedded flash param values being re-written.
The provider needs to return the resulting boolean from the base provider like..
if (base.ConvertToExternalInternal(url,internalObject, encoding))
{
url.Path = url.Path.ToLower();
return true;
}
return false;
Mash - thanks for the amend
Post a Comment