protected void Page_Load(object sender, EventArgs e)
 {
     if (!UserValidationFacade.IsLoggedIn())
     {
         LegacyUrlHandlerFacade.RedirectToLoginPage();
     }
 }
        protected void btnRemoveRedundantPaths_Click(object sender, EventArgs e)
        {
            var mappings = LegacyUrlHandlerFacade.GetMappingsFromXml().RawLinks;
            var siteMap  = LegacyUrlHandlerFacade.GetMappingsFromSiteMap();

            foreach (var m in siteMap)
            {
                var oldPath = m.Key;

                if (mappings.ContainsKey(oldPath))
                {
                    mappings.Remove(oldPath);
                }
            }

            LegacyUrlHandlerFacade.WriteXml(mappings);
            btnRemoveRedundantPaths.Visible = false;
            lblResult.Text = "Redundant paths are removed.";
        }
        protected void btnStoreCurrentPaths_Click(object sender, EventArgs e)
        {
            var mappings = LegacyUrlHandlerFacade.GetMappingsFromXml().RawLinks;
            var siteMap  = LegacyUrlHandlerFacade.GetMappingsFromSiteMap();

            foreach (var m in siteMap)
            {
                var pageId  = m.Value;
                var oldPath = m.Key;
                var newPath = string.Format("~/page({0})", pageId);

                if (!mappings.ContainsKey(oldPath))
                {
                    mappings.Add(oldPath, newPath);
                }
            }

            LegacyUrlHandlerFacade.WriteXml(mappings);
            btnStoreCurrentPaths.Visible = false;
            lblResult.Text = "Current paths are stored. Please make required changes to website and press 'Remove Redundant Paths' url above.";
        }
예제 #4
0
        void context_BeginRequest(object sender, EventArgs e)
        {
            const string cacheKey    = "LegacyUrlHandler";
            var          application = (HttpApplication)sender;
            var          context     = application.Context;
            var          request     = context.Request;

            var requestPath     = request.Path;
            var requestPathInfo = "";

            int pathInfoTokenIndex = requestPath.IndexOf(PathInfoToken);

            if (pathInfoTokenIndex > -1)
            {
                requestPathInfo = requestPath.Substring(pathInfoTokenIndex + _pathInfoTokenLength - 1);
                requestPath     = requestPath.Substring(0, pathInfoTokenIndex + _pathInfoTokenLength - 1);
            }

            //LoggingService.LogInformation("Legacy URL in:", string.Format("{0} - {1}", requestPath, requestPathInfo));
            LegacyUrlHandlerFacade.UrlMappings legacyUrlMappings;

            if (!Cache.Get(cacheKey, out legacyUrlMappings))
            {
                legacyUrlMappings = LegacyUrlHandlerFacade.GetMappingsFromXml();
                Cache.Add(cacheKey, legacyUrlMappings, LegacyUrlHandlerFacade.XmlFileName);
            }

            string mappingPath = legacyUrlMappings.GetMappedUrl(request.Url.Host, requestPath);

            if (mappingPath == null)
            {
                return;
            }


            if (PageUrlHelper.IsInternalUrl(mappingPath) || PageUrlHelper.IsPublicUrl(mappingPath))
            {
                var pageUrlOptions = PageUrls.ParseUrl(mappingPath);
                if (pageUrlOptions != null)
                {
                    var publicUrl = PageUrls.BuildUrl(pageUrlOptions, UrlKind.Public, new UrlSpace());
                    if (publicUrl != requestPath)
                    {
                        if (!string.IsNullOrEmpty(requestPathInfo))
                        {
                            publicUrl = string.Format("{0}{1}", publicUrl, requestPathInfo);
                        }

                        var queryString = context.Request.QueryString;
                        if (queryString.Count > 0)
                        {
                            publicUrl = string.Format("{0}{1}?{2}", publicUrl, requestPathInfo, queryString);
                        }

                        context.Response.RedirectPermanent(publicUrl, true);
                    }
                }
            }
            else
            {
                context.Response.RedirectPermanent(mappingPath, true);
            }
        }