Beispiel #1
0
        /// <summary>
        /// This method reads the promo url mapping and populates the PromoUrls dictionary object
        /// The key is name of the promo url and the value is an object of promourl.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadXml(System.Xml.XmlReader reader)
        {
            XmlSerializer valueSerializer = new XmlSerializer(typeof(PromoUrl));

            if (reader.IsEmptyElement)
            {
                return;
            }

            // Read to PromoUrls element
            reader.Read();
            if (reader.IsEmptyElement)
            {
                return;
            }

            while (reader.Read())
            {
                if (reader.LocalName == "PromoUrl")
                {
                    //Create instance of promo url
                    PromoUrl promoUrl = new PromoUrl();
                    string   key      = reader.GetAttribute("Name");
                    if (!string.IsNullOrEmpty(key))
                    {
                        key           = key.ToLower().Trim();
                        promoUrl.Name = key;
                        reader.Read();
                        String mappedUrl = reader.ReadString();
                        if (string.IsNullOrEmpty(mappedUrl)) // If the mapped URL is missing, skip this one.
                        {
                            continue;
                        }
                        promoUrl.MappedTo = mappedUrl.Trim();
                        if (!PromoUrls.ContainsKey(key))
                        {
                            PromoUrls.Add(key, promoUrl);
                        }
                        reader.ReadEndElement();
                    }
                    else
                    {
                        throw new Exception("name attribute cannot be null for the Promo URL");
                    }
                }
            }
        }
Beispiel #2
0
        void OnBeginRequest(object sender, EventArgs e)
        {
            context = ((HttpApplication)sender).Context;

            // Get absolute path of the request URL as pretty URL
            String url = context.Server.UrlDecode(context.Request.Url.AbsolutePath);

            if (Utility.IgnoreWebResource(url))
            {
                return;
            }

            //Check if the PageAssemblyInstruction is not null then it was processed as pretty url.
            if (PageAssemblyContext.Current.PageAssemblyInstruction != null)
            {
                return;
            }

            try
            {
                //Check if Promo Url information is in the Application State
                PromoUrlMapping promoUrlMapping            = null;
                bool            reLoad                     = (bool)context.Application["reloadPromoUrlMappingInfo"];
                bool            promoUrlMappingFileChanged = IsPromoUrlMappingFileChanged("/");

                if (context.Application["PromoUrlMapping"] != null && !reLoad && !promoUrlMappingFileChanged)
                {
                    promoUrlMapping = (PromoUrlMapping)context.Application["PromoUrlMapping"];
                }
                else
                {
                    context.Application.Lock();
                    FileInfo        fileInfo             = null;
                    PromoUrlMapping freshPromoUrlMapping = PromoUrlMappingInfoFactory.GetPromoUrlMapping("/", ref fileInfo);
                    if (freshPromoUrlMapping != null)
                    {
                        context.Application["reloadPromoUrlMappingInfo"] = false;
                        context.Application["PromoUrlMapping"]           = freshPromoUrlMapping;
                        CachedPromoMappingFileInfo = fileInfo;
                    }
                    context.Application.UnLock();

                    // Log an event saying the promo url mapping file was loaded
                    log.DebugFormat("Promo Url Mapping file successfully loaded reLoad: {0}, promoUrlMappingFileChanged: {1}",
                                    reLoad, promoUrlMappingFileChanged);
                }

                promoUrlMapping = (PromoUrlMapping)context.Application["PromoUrlMapping"];

                if (promoUrlMapping != null)
                {
                    PromoUrl promoUrl = null;
                    if (promoUrlMapping.PromoUrls.ContainsKey(url.ToLower()))
                    {
                        promoUrl = promoUrlMapping.PromoUrls[url.ToLower()];
                        string mappedToUrl = promoUrl.MappedTo + (string.IsNullOrEmpty(context.Request.Url.Query) ? "?redirect=true" : context.Request.Url.Query);

                        // Add redirect parameter for analytics (if not previously redirected)
                        if (!string.IsNullOrEmpty(context.Request.Url.Query))
                        {
                            mappedToUrl += (!context.Request.Url.Query.Contains("redirect=true") ? "&redirect=true" : String.Empty);
                        }


                        // If the original request is post then save target promo url
                        // for use in the page instructions assembly loader.
                        if (context.Request.RequestType == "POST")
                        {
                            context.RewritePath(mappedToUrl);
                        }
                        else
                        {
                            NCI.Web.CDE.Application.PermanentRedirector.DoPermanentRedirect(context.Response, mappedToUrl, "Promo Url");
                        }
                    }
                    else if (!url.EndsWith("/") && promoUrlMapping.PromoUrls.ContainsKey(url.ToLower() + "/"))
                    {
                        promoUrl = promoUrlMapping.PromoUrls[url.ToLower() + "/"];
                        string mappedToUrl = promoUrl.MappedTo + (string.IsNullOrEmpty(context.Request.Url.Query) ? "?redirect=true" : context.Request.Url.Query);

                        // Add redirect parameter for analytics (if not previously redirected)
                        if (!string.IsNullOrEmpty(context.Request.Url.Query))
                        {
                            mappedToUrl += (!context.Request.Url.Query.Contains("redirect=true") ? "&redirect=true" : String.Empty);
                        }

                        // If the original request is post then save target promo url
                        // for use in the page instructions assembly loader.
                        if (context.Request.RequestType == "POST")
                        {
                            context.RewritePath(mappedToUrl);
                        }
                        else
                        {
                            NCI.Web.CDE.Application.PermanentRedirector.DoPermanentRedirect(context.Response, mappedToUrl, "Promo Url");
                        }
                    }
                    else
                    {
                        //1. Remove last part of path, e.g. /cancertopics/wyntk/bladder/page10 becomes /cancertopics/wyntk/bladder
                        string truncUrl  = url.Substring(0, url.LastIndexOf('/'));
                        string appendUrl = url.Substring(url.LastIndexOf('/'));

                        if (truncUrl != string.Empty)
                        {
                            if (promoUrlMapping.PromoUrls.ContainsKey(truncUrl.ToLower()))
                            {
                                promoUrl = promoUrlMapping.PromoUrls[truncUrl.ToLower()];
                                string mappedToUrl = promoUrl.MappedTo + appendUrl + (string.IsNullOrEmpty(context.Request.Url.Query) ? "?redirect=true" : context.Request.Url.Query);

                                // Add redirect parameter for analytics (if not previously redirected)
                                if (!string.IsNullOrEmpty(context.Request.Url.Query))
                                {
                                    mappedToUrl += (!context.Request.Url.Query.Contains("redirect=true") ? "&redirect=true" : String.Empty);
                                }

                                if (context.Request.RequestType == "POST")
                                {
                                    context.RewritePath(mappedToUrl);
                                }
                                else
                                {
                                    NCI.Web.CDE.Application.PermanentRedirector.DoPermanentRedirect(context.Response, mappedToUrl, "Promo Url multi-page");
                                }
                            }
                        }
                        else
                        {
                            log.DebugFormat("OnBeginRequest(): Promo Url Mapping information not found for {0}", url);
                        }
                    }
                }
                else
                {
                    log.Warn("OnBeginRequest(): No Promo Url Mapping information");
                }
            }
            catch (System.Threading.ThreadAbortException)
            { }
            catch (Exception ex)
            {
                log.Error("OnBeginRequest(): Failed to Process Promo URL - " + url, ex);
            }
        }