private LinkEntry CreateLinkEntry(ResultExecutingContext context, string href, string rel, string sizes = null, string type = null, string colour = null) { var entry = new LinkEntry { Href = $"{context.HttpContext.Request.PathBase}/{href}", Rel = rel }; if (!string.IsNullOrWhiteSpace(type)) { entry.Type = type; } if (!string.IsNullOrWhiteSpace(sizes)) { entry.AddAttribute("sizes", sizes); } if (!string.IsNullOrWhiteSpace(colour)) { entry.AddAttribute("color", colour); } return(entry); }
public void Displaying(ShapeDisplayingContext context) { if (!IsMobileDevice()) { return; } var shapeMetadata = context.ShapeMetadata; if (shapeMetadata.Type != "HeadLinks" && shapeMetadata.Type != "Metas") { return; } var workContext = _workContextAccessor.GetContext(_httpContextAccessor.Current()); var resourceManager = workContext.Resolve <IResourceManager>(); if (shapeMetadata.Type == "HeadLinks") { // <link rel="alternate" type="text/html" media="handheld" href="" /> var handheldLink = new LinkEntry { Type = "text/html", Rel = "alternate", Href = "" }; handheldLink.AddAttribute("media", "handheld"); resourceManager.RegisterLink(handheldLink); // Set the transcoding protection http response headers workContext.HttpContext.Response.Cache.SetNoTransforms(); workContext.HttpContext.Response.AppendHeader("Vary", "User-Agent"); } else if (shapeMetadata.Type == "Metas") { resourceManager.SetMeta(new MetaEntry { // HACK: Orchard doesn't allow metas without a name. Name = "no-transform", HttpEquiv = "Cache-control", Content = "no-transform" }); } }