Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rawUrl"></param>
        /// <returns></returns>
        /// <exception cref="CustomRoutingException"></exception>
        public string MapUrlToFile(string rawUrl)
        {
            List <ConfigurationObject.RouteMapping> collection = WebsiteConfig.CustomPageMapping;

            foreach (ConfigurationObject.RouteMapping routeObject in collection)
            {
                // all URLs are normalized
                List <string> normalizedRoutes = new List <string>();
                foreach (string nonNormalizedRoute in routeObject.Routes)
                {
                    normalizedRoutes.Add(UrlRewriting.NormalizeUrl(nonNormalizedRoute));
                }

                if (normalizedRoutes.Contains(UrlRewriting.NormalizeUrl(rawUrl))) // raw URL is normalized as well
                {
                    string physicalFileUrl = routeObject.File;
                    string path            = RelativeThemePathToRootRelativePath(physicalFileUrl);
                    if (System.IO.File.Exists(path))
                    {
                        // path can't contain spaces in form of %20
                        return(path.Replace("%20", " "));
                    }
                    else
                    {
                        throw new CustomRoutingException("Required view is specified in jasper.json file, but could not be found physically: " + path);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
 public bool IsHomePage(string rawUrl)
 {
     foreach (string homeRouteUrl in GetHomePageUrls())
     {
         if (UrlRewriting.CompareUrls(rawUrl, homeRouteUrl))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #3
0
        /// <summary>
        /// This method takes nice url, for instance /Home/Article/my_first_article and returns appropriate articleId from the database.
        /// In case of failure returns -1;
        /// </summary>
        /// <param name="inputURL"></param>
        /// <param name="dataService"></param>
        /// <returns></returns>
        public static int ReturnArticleIdFromNiceUrl(string inputURL, IJasperDataServicePublic dataService)
        {
            try
            {
                inputURL = UrlRewriting.NormalizeUrl(inputURL);

                // mydomain.cz + /Home/Articles
                string articlesRoute = UrlRewriting.NormalizeUrl(Configuration.WebsiteConfig.ArticleRoute);

                if (inputURL.StartsWith(articlesRoute))
                {
                    int ix = inputURL.IndexOf(articlesRoute);
                    if (ix != -1)
                    {
                        string requestedArticleUrl = inputURL.Substring(ix + articlesRoute.Length);

                        // database stores URL without slashes:
                        requestedArticleUrl = requestedArticleUrl.Replace("/", "");

                        requestedArticleUrl = requestedArticleUrl.Replace("%20", " "); // in case custom URL contains space (in DB is space not saved as %20)
                        int articleId = dataService.Database.UrlRewrite.Where(ur => ur.Url == requestedArticleUrl).Select(s => s.ArticleId).Single();

                        //  string relativeUrl= inputURL.Replace(requestedArticleUrl, "?id=" + articleId);

                        return(articleId);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            catch
            {
                return(-1);
            }
        }
Beispiel #4
0
        /// <summary>
        /// If the provided URL begins with "ArticleRoute" value from theme jasper.json, true will be returned, otherwise false.
        /// </summary>
        /// <param name="inputURL"></param>
        /// <returns></returns>
        /// <exception cref="InvalidUrlRewriteException"></exception>
        public static bool IsUrlRewriteRequest(string inputURL)
        {
            try
            {
                string articlesRoute = UrlRewriting.NormalizeUrl(Configuration.WebsiteConfig.ArticleRoute);
                inputURL = UrlRewriting.NormalizeUrl(inputURL);

                if (inputURL.StartsWith(articlesRoute))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidUrlRewriteException(ex);
            }
        }