コード例 #1
0
        private static void OnApplicationRequestStart(object sender, EventArgs e)
        {
            try
            {
                HttpApplication application = (HttpApplication) sender;
                SageContext context = new SageContext(application.Context);

                if (File.Exists(context.Request.PhysicalPath))
                    return;

                QueryString query = new QueryString(HttpContext.Current.Request.Url.Query);
                string view = query.GetString(MetaViewDictionary.ParamNameMetaView);
                if (view != null && !context.ProjectConfiguration.MetaViews.ContainsKey(view))
                    view = null;

                //// \.(html|xml|xmlx|htmlx)$
                //// Meta view extension gets removed from the path
                //// Path is rewritten with ?view=$1

                string path = MetaExtensionRewriter.MetaViewExpression.Replace(context.Request.Path, delegate(Match m)
                {
                    if (view == null)
                        view = m.Groups[1].Value;

                    return string.Empty;
                });

                if (view != null)
                {
                    query.Remove(MetaViewDictionary.ParamNameMetaView);
                    query.Add(MetaViewDictionary.ParamNameMetaView, view);

                    string newUri = new Uri(path + query.ToString("?"), UriKind.RelativeOrAbsolute).ToString();
                    log.DebugFormat("Rewriting the context path from '{0}' to '{1}'.", context.Request.Path, newUri);
                    application.Context.RewritePath(newUri);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Failed to rewrite path: {0}", ex.Message);
            }
        }
コード例 #2
0
ファイル: PathResolver.cs プロジェクト: igorfrance/sage
        /// <summary>
        /// Substitutes any placeholders in the specified <paramref name="templatePath"/> with values from the current 
        /// <see cref="ProjectConfiguration"/>, the current <see cref="SageContext"/> and the specified 
        /// <paramref name="category"/>.
        /// </summary>
        /// <param name="templatePath">The path to resolve.</param>
        /// <param name="category">The category to use instead of the current context's category when resolving.</param>
        /// <returns>The substituted version of the specified <paramref name="templatePath"/>.</returns>
        public string Substitute(string templatePath, string category)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(templatePath));
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(category));

            QueryString values = new QueryString();
            values.Add("category", category);
            values.Add("resourcepath", this.GetAssetPath(category));

            return this.Substitute(templatePath, values);
        }
コード例 #3
0
ファイル: PathResolver.cs プロジェクト: igorfrance/sage
        /// <summary>
        /// Substitutes any placeholders in the specified <paramref name="templatePath"/> with values from the current 
        /// <see cref="ProjectConfiguration"/> and the specified <paramref name="values"/>.
        /// </summary>
        /// <param name="templatePath">The template path to resolve.</param>
        /// <param name="values">The name/value collection of values to use</param>
        /// <returns>
        /// The substituted version of the specified template with placeholders substituted.
        /// </returns>
        public string Substitute(string templatePath, QueryString values)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(templatePath));
            Contract.Requires<ArgumentNullException>(values != null);

            if (values["category"] == null)
                values.Add("category", context.Category);
            if (values["locale"] == null)
                values.Add("locale", context.Locale);
            if (values["assetpath"] == null)
                values.Add("assetpath", this.GetAssetPath(values["category"]));

            string result = templatePath;
            foreach (string key in values)
                result = result.Replace(string.Format("{{{0}}}", key), values[key]);

            return result;
        }
コード例 #4
0
ファイル: QueryString.cs プロジェクト: adamnoffie/Lib
        /// <summary>
        /// Returns the QueryString for a specified url
        /// </summary>
        /// <param name="url">The Url to pull the QueryString from</param>
        /// <returns>QueryString</returns>
        public static QueryString FromUrl(string url)
        {
            string[] parts = url.Split("?".ToCharArray());
            QueryString qs = new QueryString();
            qs.document = parts[0];

            if (parts.Length == 1)
                return qs;

            string[] keys = parts[1].Split("&".ToCharArray());
            foreach (string key in keys)
            {
                string[] part = key.Split("=".ToCharArray());
                if (part.Length == 1)
                    qs.Add(part[0], "");
                else if (part.Length > 1)
                    qs.Add(part[0], part[1]);
            }
            return qs;
        }