これは私がやったことです - 少なくとも今のところ:
検索して置換:
html.image("~
為に
Html.CDNImage("~
そして、静的クラスでヘルパーを作成しましたImageExtensions
:
public static string CDNImage(this HtmlHelper htmlHelper, string imageRelativeUrl)
{
return CDNImage(htmlHelper, imageRelativeUrl, null, null);
}
public static string CDNImage(this HtmlHelper htmlHelper, string imageRelativeUrl, object htmlAttributes)
{
return CDNImage(htmlHelper, imageRelativeUrl, null, htmlAttributes);
}
public static string CDNImage(this HtmlHelper htmlHelper, string imageRelativeUrl, string alt, object htmlAttributes)
{
string url = Regex.Replace(imageRelativeUrl, "~/content/", "http://s3.amazon.com/", RegexOptions.Compiled | RegexOptions.IgnoreCase);
return htmlHelper.Image(url, alt, htmlAttributes);
}
明らかにs3.amazon.com
、ここではプレースホルダーとして使用しています。CDN の URL を入力する必要があります。
必要に応じて、何らかの構成プロパティを使用して、実際に置換を行うかどうかを判断できます。