Beispiel #1
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string inputPath        = Request.Url.LocalPath.ToLower();
            string inputQueryString = Request.QueryString.ToString();

            string siteid    = ConfigurationManager.AppSettings["SiteID"];
            string outputUrl = "";

            bool isEditMode = (Request.QueryString["mode"] == "edit");

            //Genereer het werkelijke path en controlleer of het een echt bestand is of dat het een virtueel bestand is.
            //string serverPath = Server.MapPath("") + inputPath;
            //serverPath = serverPath.Replace("/", "\\");
            if (inputPath.StartsWith("/_bit") || inputPath == "/page.aspx") //|| File.Exists(serverPath))
            {
                return;
            }
            else if (inputPath.EndsWith(".css") || inputPath.EndsWith(".js"))
            {
                if (inputPath.Contains("jquery-1.8.2.js") || inputPath.Contains("bit") || inputPath.Contains("jquery.iframe-post-form.js") || inputPath.Contains("JSON.js"))
                {
                    return;
                }
                string scriptid = CmsScript.GetScriptIDByUrl(inputPath, siteid);
                //Geen script ID? Dan gewoon de orginele URL doorsturen.
                if (scriptid == "" || scriptid == null)
                {
                    return;
                }
                outputUrl = "/script.handler?scriptid=" + scriptid;
                Context.RewritePath(outputUrl);
            }
            else
            {
                outputUrl = UrlRewriter.GetOriginalUrl(inputPath, inputQueryString, siteid, isEditMode);
            }

            //Reload bitBundler na dat een backup is terug gezet.
            if (Request.QueryString.AllKeys.Contains("ReloadScripts"))
            {
                BitBundler.Init();
            }

            if (outputUrl != string.Empty)
            {
                Context.RewritePath(outputUrl);
            }
        }
Beispiel #2
0
        public static void FillSearchIndex(string relativeUrl, CmsSite site)
        {
            if (allUrls.ContainsKey(relativeUrl))
            {
                return;
            }
            allUrls.Add(relativeUrl, "");
            //voor Server.Execute altijd complete url nodig
            string originalUrl = UrlRewriter.GetOriginalUrl(relativeUrl, "", site.ID.ToString(), false);
            string htmlOutput  = ExecuteUrl(originalUrl);

            if (htmlOutput == "")
            {
                return;
            }

            string fk_datacollection = string.Empty;
            string searchItemType    = "Page";

            if (originalUrl.Contains("dataid="))
            {
                fk_datacollection = tryGetFKDataCollection(originalUrl, out searchItemType);
            }
            HtmlDocument doc = new HtmlDocument();

            try
            {
                doc.LoadHtml(htmlOutput);

                //gegevens verzamelen voor in searchindex record
                string bodyContent = doc.DocumentNode.InnerHtml;
                //string textOnlyPageContent = removeHTMLTags(bodyContent);
                string   textOnlyPageContent = Utils.HtmlToText.StripHTML(bodyContent);
                string   title               = doc.DocumentNode.Descendants("title").SingleOrDefault().InnerText;
                string   metaDescription     = "";
                HtmlNode metaDescriptionNode = doc.DocumentNode.SelectSingleNode("//meta[@name='description']");//meta[@name='description']
                if (metaDescriptionNode != null)
                {
                    metaDescription = metaDescriptionNode.GetAttributeValue("content", "");
                }
                string   metaKeywords     = "";
                HtmlNode metaKeywordsNode = doc.DocumentNode.SelectSingleNode("//meta[@name='keywords']");//meta[@name='description']
                if (metaKeywordsNode != null)
                {
                    metaKeywords = metaKeywordsNode.GetAttributeValue("content", "");
                }

                //Search item opslaan
                SearchResultItem indexItem = new SearchResultItem();
                indexItem.Name            = relativeUrl;
                indexItem.Type            = searchItemType;
                indexItem.Title           = title;
                indexItem.MetaDescription = metaDescription;
                indexItem.MetaKeywords    = metaDescription;
                indexItem.Content         = textOnlyPageContent;
                indexItem.Site            = site;
                indexItem.Url             = relativeUrl;

                indexItem.FK_DataCollection = fk_datacollection;
                indexItem.Save();


                //zoek naar doorlink urls
                foreach (HtmlNode elm in doc.DocumentNode.Descendants("a"))
                {
                    string href = elm.GetAttributeValue("href", "href");
                    if (isInternalPageLink(href, site))
                    {
                        try
                        {
                            href = href.Replace(site.DomainName, "");

                            if (!allUrls.ContainsKey(href))
                            {
                                FillSearchIndex(href, site);
                            }
                        }
                        catch (Exception ex) { }
                    }
                }
            }
            catch (Exception ex) { }
        }