Skip to content

Instantly share code, notes, and snippets.

@robertpateii
Last active August 29, 2015 13:58
Show Gist options
  • Save robertpateii/10028833 to your computer and use it in GitHub Desktop.
Save robertpateii/10028833 to your computer and use it in GitHub Desktop.
Quick Link Provider I wrote to deliver HTTPS links. Sample code for my comment on [SSL Link Provider](http://marketplace.sitecore.net/en/Modules/SSL_Link_Provider.aspx) on the Sitecore Marketplace. Running Sitecore version 6.5.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Change.This.To.Suit.Your.Application
{
class SecureLinkProvider : Sitecore.Links.LinkProvider
{
public string SSLRequiredValue { get; set; }
public string AgnosticValue { get; set; }
public string SSLRequiredValue { get; set; }
public override string GetItemUrl(Sitecore.Data.Items.Item item, Sitecore.Links.UrlOptions options)
{
string requireSSL = item.Fields["Require SSL"];
if (!requireSSL.IsNullOrEmpty() && requireSSL == "Require SSL")
{
options.AlwaysIncludeServerUrl = true;
string baseUrl = base.GetItemUrl(item, options);
UriBuilder urlBuilder = new UriBuilder(baseUrl);
urlBuilder.Scheme = "https";
urlBuilder.Port = -1; // removes port from the URL so the default for the scheme is used
return urlBuilder.ToString();
}
else
{
return base.GetItemUrl(item, options);
}
}
}
}
@robertpateii
Copy link
Author

If you're using something like this let me also recommend that you use the Robots element to tell search engines to INDEX but NO FOLLOW the links on your HTTPS pages if your main site is in HTTP. This will help avoid duplicate content issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment