public static bool IsThemeable(string file) { var themeDirectory = Url.ResolveTokens("{ThemesUrl}").ToLower(); if (!file.StartsWith("~")) { file = "~" + file; } var isThemeable = file.StartsWith("~" + themeDirectory, StringComparison.InvariantCultureIgnoreCase); return(isThemeable); }
/// <summary>Renders a script that loads the given action asynchronously from the client.</summary> /// <param name="routeParams">The route parameters to use for building the url.</param> /// <returns>A content result with a load action script.</returns> protected virtual ActionResult AsyncView(RouteValueDictionary routeParams) { if (!routeParams.ContainsKey(ContentRoute.ContentPartKey)) { routeParams[ContentRoute.ContentPartKey] = CurrentItem.ID; } string id = "part_" + routeParams[ContentRoute.ContentPartKey]; N2.Web.Url url = CurrentPage.Url; url = url.UpdateQuery(routeParams); return(Content(string.Format(@"<div id='{0}' class='async loading'></div><script type='text/javascript'>//<![CDATA[ jQuery('#{0}').load('{1}');//]]></script>", id, url))); }
public static string GetThemedFile(string file, string theme) { // n2's zip provider doesn't support ../../, so lets try to fix it manually var regex = new Regex(@"([^/]*/\.\./)"); while (regex.IsMatch(file)) { file = regex.Replace(file, ""); } file = file.Replace("\\\\", "\\").Replace("\\", "/"); if (file.StartsWith("/")) { file = "~" + file; } if (!IsThemeable(file)) { return(file); } HttpContext.Current.Items["theme"] = theme; var themeDirectory = Url.ResolveTokens("{ThemesUrl}").ToLower(); var themedLocation = file.Replace("~" + themeDirectory, ""); themedLocation = themedLocation.Substring(themedLocation.IndexOf("/", StringComparison.Ordinal)); var helper = new UrlHelper(HttpContext.Current.Request.RequestContext); var result = helper.ThemedContent(themedLocation); if (System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(result)) { return(System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(result).VirtualPath); } return(result); }