/// <summary>
        /// BindData fetches the data from the database and updates the controls
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/17/2005	documented
        /// </history>
        private void BindData()
        {
            if( Request.QueryString["paid"] != null )
            {
                PortalAliasInfo objPortalAliasInfo;
                int intPortalAliasID = Convert.ToInt32( Request.QueryString["paid"] );

                PortalAliasController p = new PortalAliasController();
                objPortalAliasInfo = p.GetPortalAliasByPortalAliasID( intPortalAliasID );

                ViewState.Add( "PortalAliasID", intPortalAliasID );
                ViewState.Add( "PortalID", objPortalAliasInfo.PortalID );

                if( ! UserInfo.IsSuperUser )
                {
                    if( objPortalAliasInfo.PortalID != PortalSettings.PortalId )
                    {
                        UI.Skins.Skin.AddModuleMessage( this, "You do not have access to view this Portal Alias.", ModuleMessageType.RedError );
                        return;
                    }
                }

                txtAlias.Text = objPortalAliasInfo.HTTPAlias;
                SetDeleteVisibility( objPortalAliasInfo.PortalID );
            }
            else if( Request.QueryString["pid"] != "" )
            {
                if( UserInfo.IsSuperUser )
                {
                    ViewState.Add( "PortalID", Convert.ToInt32( Request.QueryString["pid"] ) );
                }
                SetDeleteVisibility( Convert.ToInt32( Request.QueryString["pid"] ) );
            }
            else
            {
                ViewState.Add( "PortalID", PortalSettings.PortalId );
                SetDeleteVisibility( PortalSettings.PortalId );
            }
        }
Пример #2
0
        private static void AddCustomRedirectsToDictionary(SharedDictionary<string, string> tabIndex,
                                                    Dictionary<string, DupKeyCheck> dupCheck,
                                                    string httpAlias,
                                                    TabInfo tab,
                                                    FriendlyUrlSettings settings,
                                                    FriendlyUrlOptions options,
                                                    ref string rewritePath,
                                                    out int tabPathDepth,
                                                    ref List<string> customHttpAliasesUsed,
                                                    bool isDeleted,
                                                    Guid parentTraceId)
        {
            tabPathDepth = 1;
            var duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabRedirected;
            bool checkForDupUrls = settings.CheckForDuplicateUrls;
            //697 : custom url rewrites with large number of path depths fail because of incorrect path depth calculation
            int maxTabPathDepth = 1;
            string newRewritePath = rewritePath;
            string aliasCulture = null;
            //get the culture for this alias
            var primaryAliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(tab.PortalID).ToList();

            if (primaryAliases.Count > 0)
            {
                aliasCulture = primaryAliases.GetCultureByPortalIdAndAlias(tab.PortalID, httpAlias);
            }
            foreach (var redirect in tab.TabUrls)
            {
                //allow for additional qs parameters
                if (!String.IsNullOrEmpty(redirect.QueryString))
                {
                    rewritePath += (redirect.QueryString.StartsWith("&")) ? redirect.QueryString : "&" + redirect.QueryString;
                }

                string redirectTabPath = redirect.Url;
                string redirectedRewritePath = rewritePath;

                //770 : allow for custom portal aliases
                string redirectAlias = httpAlias;
                if (redirect.PortalAliasId > 0)
                {
                    //has a custom portal alias
                    var pac = new PortalAliasController();
                    PortalAliasInfo customAlias = pac.GetPortalAliasByPortalAliasID(redirect.PortalAliasId);
                    if (customAlias != null)
                    {
                        //this will be used to add the Url to the dictionary
                        redirectAlias = customAlias.HTTPAlias;
                        //add to the list of custom aliases used by the portal
                        if (customHttpAliasesUsed == null)
                        {
                            customHttpAliasesUsed = new List<string>();
                        }
                        if (!customHttpAliasesUsed.Contains(redirectAlias))
                        {
                            customHttpAliasesUsed.Add(redirectAlias);
                        }
                    }
                }
                //set the redirect status using the httpStatus
                switch (redirect.HttpStatus)
                {
                    case "301":
                        redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                        ActionType.Redirect301,
                                                                                        RedirectReason.Custom_Redirect);
                        break;
                    case "302":
                        redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                        ActionType.Redirect302,
                                                                                        RedirectReason.Custom_Redirect);
                        break;
                    case "404":
                        redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                        ActionType.Output404,
                                                                                        RedirectReason.Custom_Redirect);
                        break;
                    case "200":
                        //when there is a 200, then replace the 'standard' path
                        newRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(newRewritePath,
                                                                                        ActionType.CheckFor301,
                                                                                        RedirectReason.Custom_Redirect);
                        //672 : replacement urls have preference over all redirects, deleted tabs and standard urls
                        duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabOK;
                        break;
                }
                //check the culture of the redirect to see if it either doesn't match the alias or needs to specify
                //the language when requested
                if (redirect.CultureCode != null)
                {
                    if (redirect.CultureCode != "" && redirect.CultureCode != "Default")
                    {
                        //806 : specify duplicates where the alias culture doesn't match the redirect culture
                        //so that redirect to the best match between alias culture and redirect culture
                        //compare the supplied alias culture with the redirect culture
                        //856 : if alias culture == "" and a custom 301 redirect then redirects are forced
                        if (!string.IsNullOrEmpty(aliasCulture) && aliasCulture != redirect.CultureCode)
                        {
                            //the culture code and the specific culture alias don't match
                            //set 301 check status and set to delete if a duplicate is found
                            redirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(
                                                                                redirectedRewritePath,
                                                                                ActionType.CheckFor301,
                                                                                RedirectReason.Custom_Redirect);
                            newRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(newRewritePath,
                                                                                ActionType.CheckFor301,
                                                                                RedirectReason.Custom_Redirect);
                            duplicateHandlingPreference = UrlEnums.TabKeyPreference.TabRedirected;
                        }
                        //add on the culture code for the redirect, so that the rewrite silently sets the culture for the page
                        RewriteController.AddLanguageCodeToRewritePath(ref redirectedRewritePath, redirect.CultureCode);
                    }
                }
                //now add the custom redirect to the tab dictionary
                if (String.Compare(httpAlias, redirectAlias, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AddToTabDict(tabIndex,
                                    dupCheck,
                                    httpAlias,
                                    redirectTabPath,
                                    redirectedRewritePath,
                                    tab.TabID,
                                    duplicateHandlingPreference,
                                    ref tabPathDepth,
                                    checkForDupUrls,
                                    isDeleted);
                }
                else
                {
                    //770 : there is a specific alias for this tab
                    //if not a redirect already, make it a redirect for the wrong (original) rewrite path
                    string wrongAliasRedirectedRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(redirectedRewritePath,
                                                                                                            ActionType.Redirect301,
                                                                                                            RedirectReason.Custom_Tab_Alias);
                    //add in the entry with the specific redirectAlias
                    if (redirectTabPath == "")
                    {
                        //when adding a blank custom Url, also add in a standard tab path url, because any url that also includes querystring data will use the standard tab path
                        string tabPath = GetTabPath(tab, options, parentTraceId);
                        string stdDictRewritePath = RedirectTokens.AddRedirectReasonToRewritePath(rewritePath,
                                                                                                  ActionType.CheckFor301,
                                                                                                  RedirectReason.Custom_Tab_Alias);
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        redirectAlias,
                                        tabPath,
                                        stdDictRewritePath,
                                        tab.TabID,
                                        UrlEnums.TabKeyPreference.TabOK,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                        //then add in the portal alias with no tabpath (ie like a site root url)
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        redirectAlias,
                                        redirectTabPath,
                                        redirectedRewritePath,
                                        tab.TabID,
                                        duplicateHandlingPreference,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                        //838 : disabled tabs with custom aliases - still load the settings page without redirect
                        //disabled / not active by date / external url pages cannot navigate to settings page
                        if (tab.DisableLink || !string.IsNullOrEmpty(tab.Url) ||
                           (tab.EndDate < DateTime.Now && tab.EndDate > DateTime.MinValue) ||
                           (tab.StartDate > DateTime.Now && tab.StartDate > DateTime.MinValue))
                        {
                            string settingsUrl = tabPath + "/ctl/Tab";
                            string settingsRewritePath = CreateRewritePath(tab.TabID, redirect.CultureCode, "ctl=Tab");
                            //no redirect on the ctl/Tab url
                            //add in the ctl/tab Url for the custom alias, with no redirect so that the page settings can be loaded
                            AddToTabDict(tabIndex,
                                            dupCheck,
                                            redirectAlias,
                                            settingsUrl,
                                            settingsRewritePath,
                                            tab.TabID,
                                            UrlEnums.TabKeyPreference.TabRedirected,
                                            ref tabPathDepth,
                                            settings.CheckForDuplicateUrls,
                                            isDeleted);
                        }
                    }
                    else
                    {
                        //add in custom entry with different alias
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        redirectAlias,
                                        redirectTabPath,
                                        redirectedRewritePath,
                                        tab.TabID,
                                        duplicateHandlingPreference,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                        //add in the entry with the original alias, plus an instruction to redirect if it's used
                        AddToTabDict(tabIndex,
                                        dupCheck,
                                        httpAlias,
                                        redirectTabPath,
                                        wrongAliasRedirectedRewritePath,
                                        tab.TabID,
                                        duplicateHandlingPreference,
                                        ref tabPathDepth,
                                        checkForDupUrls,
                                        isDeleted);
                    }
                }
                if (tabPathDepth > maxTabPathDepth)
                {
                    maxTabPathDepth = tabPathDepth;
                }
            }
            //return the highest tabpath depth found
            tabPathDepth = maxTabPathDepth;
            //return any changes to the rewritePath
            rewritePath = newRewritePath;
        }
        /// <summary>
        /// Returns a list of tab and redirects from the database, for the specified portal
        /// Assumes that the dictionary should have any existing items replaced if the portalid is specified 
        /// and the portal tabs already exist in the dictionary.
        /// </summary>
        /// <param name="existingTabs"></param>
        /// <param name="portalId"></param>
        /// <param name="settings"></param>
        /// <param name="customAliasTabs"></param>
        /// <remarks>
        ///    Each dictionary entry in the return value is a complex data type of another dictionary that is indexed by the url culture.  If there is 
        ///    only one culture for the Url, it will be that culture.
        /// </remarks>
        /// <returns></returns>
        private static SharedDictionary<int, SharedDictionary<string, string>> BuildUrlDictionary(SharedDictionary<int, SharedDictionary<string, string>> existingTabs, 
                                                    int portalId,
                                                    FriendlyUrlSettings settings, 
                                                    ref SharedDictionary<string, string> customAliasTabs)
        {
            //fetch tabs with redirects
            var tabs = FriendlyUrlController.GetTabs(portalId, false, null, settings);
            if (existingTabs == null)
            {
                existingTabs = new SharedDictionary<int, SharedDictionary<string, string>>();
            }
            if (customAliasTabs == null)
            {
                customAliasTabs = new SharedDictionary<string, string>();
            }
            

            //go through each tab in the found list            
            foreach (TabInfo tab in tabs.Values)
            {
                //check the custom alias tabs collection and add to the dictionary where necessary
                foreach (var customAlias in tab.CustomAliases)
                {
                    string key = tab.TabID.ToString() + ":" + customAlias.Key;
                    using (customAliasTabs.GetWriteLock())  //obtain write lock on custom alias Tabs
                    {
                        if (customAliasTabs.ContainsKey(key) == false)
                        {
                            customAliasTabs.Add(key, customAlias.Value);
                        }
                    }
                }

                foreach (TabUrlInfo redirect in tab.TabUrls)
                {
                    if (redirect.HttpStatus == "200")
                    {
                        string url = redirect.Url;
                        //770 : add in custom alias into the tab path for the custom Urls
                        if (redirect.PortalAliasUsage != PortalAliasUsageType.Default && redirect.PortalAliasId > 0)
                        {
                            //there is a custom http alias specified for this portal alias
                            var pac = new PortalAliasController();
                            PortalAliasInfo alias = pac.GetPortalAliasByPortalAliasID(redirect.PortalAliasId);
                            if (alias != null)
                            {
                                string customHttpAlias = alias.HTTPAlias;
                                url = customHttpAlias + "::" + url;
                            }
                        }
                        string cultureKey = redirect.CultureCode.ToLower();
                        int tabid = tab.TabID;
                        using (existingTabs.GetWriteLock())
                        {
                            if (existingTabs.ContainsKey(tabid) == false)
                            {
                                var entry = new SharedDictionary<string, string>();
                                using (entry.GetWriteLock())
                                {
                                    entry.Add(cultureKey, url);
                                }
                                //871 : use lower case culture code as key
                                existingTabs.Add(tab.TabID, entry);
                            }
                            else
                            {
                                SharedDictionary<string, string> entry = existingTabs[tabid];
                                //replace tab if existing but was retreieved from tabs call
                                if (tab.PortalID == portalId || portalId == -1)
                                {
                                    using (entry.GetWriteLock())
                                    {
                                        if (entry.ContainsKey(cultureKey) == false)
                                        {
                                            //add the culture and set in parent dictionary
                                            //871 : use lower case culture code as key
                                            entry.Add(cultureKey, url);
                                            existingTabs[tabid] = entry;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return existingTabs;
        }
        /// <summary>
        /// cmdDelete_Click runs when the Delete button is clicked
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/17/2005	documented
        /// </history>
        protected void cmdDelete_Click( Object sender, EventArgs e )
        {
            try
            {
                int intPortalAliasID;
                intPortalAliasID = Convert.ToInt32( ViewState["PortalAliasID"] );
                PortalAliasInfo objPortalAliasInfo;
                PortalAliasController p = new PortalAliasController();
                objPortalAliasInfo = p.GetPortalAliasByPortalAliasID( intPortalAliasID );

                if( ! UserInfo.IsSuperUser )
                {
                    if( objPortalAliasInfo.PortalID != PortalSettings.PortalId )
                    {
                        UI.Skins.Skin.AddModuleMessage( this, Localization.GetString( "AccessDenied", this.LocalResourceFile ), ModuleMessageType.RedError );
                        return;
                    }
                }
                p.DeletePortalAlias( intPortalAliasID );

                Response.Redirect( Convert.ToString( ViewState["UrlReferrer"] ), true );
            }
            catch( Exception exc ) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException( this, exc );
            }
        }