public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
        {
            string path = $"~/{(values["path"] ?? "").ToString().TrimEnd('/')}";

            if (path.IndexOf(".html", StringComparison.OrdinalIgnoreCase) < 0 && CustomRegex.PostIdRegex.IsMatch(path))
            {
                return(true);
            }
            var redirect = UrlRedirectService.GetItems(() => httpContext.RequestServices.GetService <IUrlRedirectService>()).Count(m => m.Status == (int)Easy.Constant.RecordStatus.Active && m.InComingUrl == path && m.InComingUrl != m.DestinationURL);

            return(redirect > 0);
        }
 public override IActionResult Create(UrlRedirect entity)
 {
     if (ModelState.IsValid)
     {
         if (!Valid(entity))
         {
             return(View(entity));
         }
         UrlRedirectService.InvalidateCachedItems();
         return(base.Create(entity));
     }
     return(View(entity));
 }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            const string pageId = "100062";

            Console.WriteLine("Fetching url for pageId " + pageId + "...");
            string url = PageIdService.GetWikipediaUrlForPageId(pageId);

            Console.WriteLine("Url is: " + url);

            Console.WriteLine();

            const string testWikipediaUrl = "https://en.wikipedia.org/wiki/Namco_Museum_Volume_1";

            Console.WriteLine("Fetching redirect url for " + testWikipediaUrl + "...");
            string destinationUrl = UrlRedirectService.GetRedirectUrlForWikipediaUrl(testWikipediaUrl);

            Console.WriteLine("Destination url is: " + destinationUrl);

            Console.WriteLine();

            Console.WriteLine("Fetching image urls for " + url + "...");
            List <string> imageUrls = ImageService.GetImageUrlsForWikipediaUrl(url);

            Console.WriteLine("Images found:");
            imageUrls.ForEach(u => Console.WriteLine("  " + u));

            Console.WriteLine();

            Console.WriteLine("Fetching InfoBox test for " + url + "...");
            string infoBoxText = InfoBoxService.GetInfoBoxTextForWikipediaUrl(url);

            Console.WriteLine("InfoBox text: " + infoBoxText);

            Console.WriteLine();

            Console.WriteLine("Getting title for InfoBox text... ");
            Console.WriteLine("Title is " + InfoBoxWikiTextParser.GetTitleForInfoBox(infoBoxText));

            Console.WriteLine();

            Console.WriteLine("Getting genre from InfoBox text... ");
            string genre = InfoBoxWikiTextParser.GetNamedElementFromInfoBox(infoBoxText, "genre");

            Console.WriteLine("Genre is " + genre);

            Console.WriteLine();

            Console.WriteLine("Getting display text for genre...");
            Console.WriteLine(genre + " => " + InternalWikiLinkParser.ExtractDisplayTextFromLink(genre));
        }
        public IActionResult RedirectTo(string path)
        {
            if (path.IsNotNullAndWhiteSpace() && path.IndexOf(".html", StringComparison.OrdinalIgnoreCase) < 0 && CustomRegex.PostIdRegex.IsMatch(path))
            {
                return(RedirectPermanent($"~/{(path ?? "")}.html"));
            }
            path = $"~/{(path ?? "").TrimEnd('/')}";
            var redirec = UrlRedirectService.GetItems(() => Service).Where(m => m.InComingUrl == path).FirstOrDefault();

            if (redirec != null)
            {
                if (redirec.IsPermanent)
                {
                    return(RedirectPermanent(redirec.DestinationURL));
                }
                else
                {
                    return(Redirect(redirec.DestinationURL));
                }
            }
            return(this.NotFoundResult());
        }
 public override IActionResult Delete(int id)
 {
     UrlRedirectService.InvalidateCachedItems();
     return(base.Delete(id));
 }