This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Settings : ConfigurationSection | |
{ | |
[ConfigurationProperty("enabled", DefaultValue = "false", IsRequired = true)] | |
public bool Enabled | |
{ | |
get { return (bool)this["enabled"]; } | |
set { this["enabled"] = value; } | |
} | |
[ConfigurationProperty("cloudFrontDomainName", DefaultValue = "", IsRequired = true)] | |
public string CloudFrontDomainName | |
{ | |
get { return (string)this["cloudFrontDomainName"]; } | |
set { this["cloudFrontDomainName"] = value; } | |
} | |
public static string SectionName { get { return "frontin"; } } | |
public static Settings Load() | |
{ | |
return (Settings)ConfigurationManager.GetSection(SectionName); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class UrlExtensions | |
{ | |
public static Lazy<Settings> Configuration { get; set; } | |
static UrlExtensions() | |
{ | |
Configuration = new Lazy<Settings>(Settings.Load); | |
} | |
public static string CdnContent(this UrlHelper helper, string path) | |
{ | |
var underlying = helper.Content(path); | |
if (!Configuration.Value.Enabled) | |
{ | |
return underlying; | |
} | |
var cloudRoot = HttpContext.Current.Request.Url.Scheme + "://" + Configuration.Value.CloudFrontDomainName; | |
return underlying.StartsWith("/") | |
? cloudRoot + underlying | |
: underlying.Replace(HttpContext.Current.Request.Url.Host, Configuration.Value.CloudFrontDomainName); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configSections> | |
<section name="frontin" type="Namespace.Settings, Assembly" requirePermission="false" /> | |
</configSections> | |
<frontin enabled="true" cloudFrontDomainName="xxxxx.cloudfront.net" /> |