Example #1
0
        public void TwoDictsShareALockWriteTest()
        {
            ILockStrategy ls = new ReaderWriterLockStrategy();
            var           d1 = new SharedDictionary <string, string>(ls);
            var           d2 = new SharedDictionary <string, string>(ls);

            using (ISharedCollectionLock readLock = d1.GetReadLock())
            {
                using (ISharedCollectionLock writeLock = d2.GetWriteLock())
                {
                    //do nothing
                }
            }
        }
Example #2
0
        public override string[] GetComponentList(Type contractType)
        {
            var components = new List <string>();

            using (_registeredComponents.GetReadLock())
            {
                foreach (KeyValuePair <Type, string> kvp in _registeredComponents)
                {
                    if (contractType.IsAssignableFrom(kvp.Key))
                    {
                        components.Add(kvp.Value);
                    }
                }
            }
            return(components.ToArray());
        }
Example #3
0
        /// <summary>
        /// Store the Url Dictionary (all tab urls / tabids) for the installation.
        /// </summary>
        /// <param name="urlDict"></param>
        /// <param name="urlPortals"></param>
        /// <param name="customAliasTabs"></param>
        /// <param name="settings"></param>
        /// <param name="reason"></param>
        /// <remarks>
        /// </remarks>
        internal void StoreFriendlyUrlIndexInCache(
            SharedDictionary <int, SharedDictionary <string, string> > urlDict,
            ConcurrentBag <int> urlPortals,
            SharedDictionary <string, string> customAliasTabs,
            FriendlyUrlSettings settings,
            string reason)
        {
            if (settings.LogCacheMessages)
            {
                this.onRemovePageIndex = this.RemovedPageIndexCallBack;
            }
            else
            {
                this.onRemovePageIndex = null;
            }

            LogRemovedReason = settings.LogCacheMessages;

            SetPageCache(UrlDictKey, urlDict, new DNNCacheDependency(this.GetTabsCacheDependency(urlPortals)), settings, this.onRemovePageIndex);
            SetPageCache(UrlPortalsKey, urlPortals, settings);
            SetPageCache(CustomAliasTabsKey, customAliasTabs, settings);

            if (settings.LogCacheMessages)
            {
                var log = new LogInfo {
                    LogTypeKey = "HOST_ALERT"
                };
                log.AddProperty("Url Rewriting Caching Message", "Friendly Url Index built and Stored in Cache.");
                log.AddProperty("Build Reason", reason);
                log.AddProperty("Cache Key", UrlDictKey);
                using (urlDict.GetReadLock())
                {
                    log.AddProperty("Item Count", urlDict.Values.Count.ToString());
                }

                log.AddProperty("Thread Id", Thread.CurrentThread.ManagedThreadId.ToString());
                log.AddProperty("Item added to cache", "Url Portals object added to cache.  Key:" + UrlPortalsKey + "  Items: " + urlPortals.Count.ToString());
                using (customAliasTabs.GetReadLock())
                {
                    log.AddProperty("Item added to cache", "Custom Alias Tabs added to cache.  Key:" + CustomAliasTabsKey + " Items: " + customAliasTabs.Count.ToString());
                }

                LogController.Instance.AddLog(log);
            }
        }
Example #4
0
        private static object GetCachedDataFromDictionary(CacheItemArgs cacheItemArgs, CacheItemExpiredCallback cacheItemExpired)
        {
            object cachedObject = null;

            bool isFound;

            using (ISharedCollectionLock readLock = dictionaryCache.GetReadLock())
            {
                isFound = dictionaryCache.TryGetValue(cacheItemArgs.CacheKey, out cachedObject);
            }

            if (!isFound)
            {
                // get object from data source using delegate
                try
                {
                    if (cacheItemExpired != null)
                    {
                        cachedObject = cacheItemExpired(cacheItemArgs);
                    }
                    else
                    {
                        cachedObject = null;
                    }
                }
                catch (Exception ex)
                {
                    cachedObject = null;
                    Exceptions.LogException(ex);
                }

                using (ISharedCollectionLock writeLock = dictionaryCache.GetWriteLock())
                {
                    if (!dictionaryCache.ContainsKey(cacheItemArgs.CacheKey))
                    {
                        if (cachedObject != null)
                        {
                            dictionaryCache[cacheItemArgs.CacheKey] = cachedObject;
                        }
                    }
                }
            }

            return(cachedObject);
        }
Example #5
0
        internal void StorePageIndexInCache(
            SharedDictionary <string, string> tabDictionary,
            SharedDictionary <int, PathSizes> portalDepthInfo,
            FriendlyUrlSettings settings,
            string reason)
        {
            this.onRemovePageIndex = settings.LogCacheMessages ? (CacheItemRemovedCallback)this.RemovedPageIndexCallBack : null;

            // get list of portal ids for the portals we are storing in the page index
            var portalIds = new List <int>();

            using (portalDepthInfo.GetReadLock())
            {
                portalIds.AddRange(portalDepthInfo.Keys);
            }

            // 783 : use cache dependency to manage page index instead of triggerDictionaryRebuild regex.
            SetPageCache(PageIndexKey, tabDictionary, new DNNCacheDependency(this.GetTabsCacheDependency(portalIds)), settings, this.onRemovePageIndex);

            SetPageCache(PageIndexDepthKey, portalDepthInfo, settings);

            LogRemovedReason = settings.LogCacheMessages;

            if (settings.LogCacheMessages)
            {
                var log = new LogInfo {
                    LogTypeKey = "HOST_ALERT"
                };

                log.AddProperty("Url Rewriting Caching Message", "Page Index built and Stored in Cache");
                log.AddProperty("Reason", reason);
                log.AddProperty("Cache Item Key", PageIndexKey);
                using (tabDictionary.GetReadLock())
                {
                    log.AddProperty("Item Count", tabDictionary.Count.ToString());
                }

                log.AddProperty("Thread Id", Thread.CurrentThread.ManagedThreadId.ToString());
                LogController.Instance.AddLog(log);
            }
        }
Example #6
0
        private static void CheckIconOnDisk(string path)
        {
            using (_iconsStatusOnDisk.GetReadLock())
            {
                if (_iconsStatusOnDisk.ContainsKey(path))
                {
                    return;
                }
            }

            using (_iconsStatusOnDisk.GetWriteLock())
            {
                if (!_iconsStatusOnDisk.ContainsKey(path))
                {
                    _iconsStatusOnDisk.Add(path, true);
                    string iconPhysicalPath = Path.Combine(Globals.ApplicationMapPath, path.Replace('/', '\\'));
                    if (!File.Exists(iconPhysicalPath))
                    {
                        Logger.WarnFormat(string.Format("Icon Not Present on Disk {0}", iconPhysicalPath));
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// [jmarino]  2011-06-16 Check for ContainsKey for a write added
        /// </summary>
        /// <param name="portalId"></param>
        /// <returns></returns>
        private static string GetCacheFolder(int portalId)
        {
            string cacheFolder;

            using (var readerLock = CacheFolderPath.GetReadLock())
            {
                if (CacheFolderPath.TryGetValue(portalId, out cacheFolder))
                {
                    return(cacheFolder);
                }
            }

            var        portalController = new PortalController();
            PortalInfo portalInfo       = portalController.GetPortal(portalId);

            string homeDirectoryMapPath = portalInfo.HomeDirectoryMapPath;


            if (!(string.IsNullOrEmpty(homeDirectoryMapPath)))
            {
                cacheFolder = string.Concat(homeDirectoryMapPath, "Cache\\Pages\\");
                if (!(Directory.Exists(cacheFolder)))
                {
                    Directory.CreateDirectory(cacheFolder);
                }
            }

            using (var writerLock = CacheFolderPath.GetWriteLock())
            {
                if (!CacheFolderPath.ContainsKey(portalId))
                {
                    CacheFolderPath.Add(portalId, cacheFolder);
                }
            }

            return(cacheFolder);
        }
        /// <summary>
        /// For the supplied options, return a tab path for the specified tab
        /// </summary>
        /// <param name="tab">TabInfo object of selected tab</param>
        /// <param name="settings">FriendlyUrlSettings</param>
        /// <param name="options"></param>
        /// <param name="ignoreCustomRedirects">Whether to add in the customised Tab redirects or not</param>
        /// <param name="homePageSiteRoot"></param>
        /// <param name="isHomeTab"></param>
        /// <param name="cultureCode"></param>
        /// <param name="isDefaultCultureCode"></param>
        /// <param name="hasPath"></param>
        /// <param name="dropLangParms"></param>
        /// <param name="customHttpAlias"></param>
        /// <param name="isCustomPath"></param>
        /// <param name="parentTraceId"></param>
        /// <remarks>751 : include isDefaultCultureCode flag to determine when using the portal default language
        /// 770 : include custom http alias output for when the Url uses a specific alias due to custom Url rules
        ///  : include new out parameter 'isCustomPath' to return whether the Url was generated from Url-Master custom url
        /// </remarks>
        /// <returns>The tab path as specified</returns>
        internal static string GetTabPath(TabInfo tab,
                                          FriendlyUrlSettings settings,
                                          FriendlyUrlOptions options,
                                          bool ignoreCustomRedirects,
                                          bool homePageSiteRoot,
                                          bool isHomeTab,
                                          string cultureCode,
                                          bool isDefaultCultureCode,
                                          bool hasPath,
                                          out bool dropLangParms,
                                          out string customHttpAlias,
                                          out bool isCustomPath,
                                          Guid parentTraceId)
        {
            string newTabPath;

            dropLangParms   = false;
            customHttpAlias = null;
            isCustomPath    = false;
            if (homePageSiteRoot && isHomeTab && !hasPath)
            // && !isDefaultCultureCode - not working for non-language specifc custom root urls
            {
                newTabPath = "/"; //site root for home page
            }
            else
            {
                //build the tab path and check for space replacement
                string baseTabPath = TabIndexController.GetTabPath(tab, options, parentTraceId);

                //this is the new tab path
                newTabPath = baseTabPath;
                //871 : case insensitive compare for culture code, all lookups done on lower case
                string cultureCodeKey = "";
                if (cultureCode != null)
                {
                    cultureCodeKey = cultureCode.ToLower();
                }

                bool checkForCustomHttpAlias = false;
                //get a custom tab name if redirects are being used
                SharedDictionary <string, string> customAliasForTabs = null;
                SharedDictionary <int, SharedDictionary <string, string> > urlDict;
                //886 : don't fetch custom urls for host tabs (host tabs can't have redirects or custom Urls)
                if (tab.PortalID > -1)
                {
                    urlDict = CustomUrlDictController.FetchCustomUrlDictionary(tab.PortalID, false, false, settings, out customAliasForTabs, parentTraceId);
                }
                else
                {
                    urlDict = new SharedDictionary <int, SharedDictionary <string, string> >();
                    //create dummy dictionary for this tab
                }

                if (ignoreCustomRedirects == false)
                {
                    //if not ignoring the custom redirects, look for the Url of the page in this list
                    //this will be used as the page path if there is one.

                    using (urlDict.GetReadLock())
                    {
                        if (urlDict.ContainsKey(tab.TabID))
                        {
                            //we want the custom value
                            string customTabPath = null;
                            SharedDictionary <string, string> tabpaths = urlDict[tab.TabID];

                            using (tabpaths.GetReadLock())
                            {
                                if (tabpaths.ContainsKey(cultureCodeKey))
                                {
                                    customTabPath = tabpaths[cultureCodeKey];
                                    dropLangParms = true;
                                    //the url is based on a custom value which has embedded language parms, therefore don't need them in the url
                                }
                                else
                                {
                                    if (isDefaultCultureCode && tabpaths.ContainsKey(""))
                                    {
                                        customTabPath = tabpaths[""];
                                        //dropLangParms = true;//drop the language parms if they exist, because this is the default language
                                    }
                                }
                            }
                            if (customTabPath != null)
                            {
                                //770 : pull out custom http alias if in string
                                int aliasSeparator = customTabPath.IndexOf("::", StringComparison.Ordinal);
                                if (aliasSeparator > 0)
                                {
                                    customHttpAlias = customTabPath.Substring(0, aliasSeparator);
                                    newTabPath      = customTabPath.Substring(aliasSeparator + 2);
                                }
                                else
                                {
                                    newTabPath = customTabPath;
                                }
                            }
                            if (newTabPath == "" && hasPath)
                            {
                                //can't pass back a custom path which is blank if there are path segments to the requested final Url
                                newTabPath = baseTabPath; //revert back to the standard DNN page path
                            }
                            else
                            {
                                isCustomPath = true; //we are providing a custom Url
                            }
                        }
                        else
                        {
                            checkForCustomHttpAlias = true;
                        }
                    }
                }
                else
                {
                    checkForCustomHttpAlias = true;
                    //always want to check for custom alias, even when we don't want to see any custom redirects
                }

                //770 : check for custom alias in these tabs
                if (checkForCustomHttpAlias && customAliasForTabs != null)
                {
                    string key = tab.TabID.ToString() + ":" + cultureCodeKey;
                    using (customAliasForTabs.GetReadLock())
                    {
                        if (customAliasForTabs.ContainsKey(key))
                        {
                            //this tab uses a custom alias
                            customHttpAlias = customAliasForTabs[key];
                            isCustomPath    = true; //using custom alias
                        }
                    }
                }

                if (!dropLangParms)
                {
                    string tabCultureCode = tab.CultureCode;
                    if (!string.IsNullOrEmpty(tabCultureCode))
                    {
                        dropLangParms = true;
                        //if the tab has a specified culture code, then drop the language parameters from the friendly Url
                    }
                }
                //make lower case if necessary
                newTabPath = AdvancedFriendlyUrlProvider.ForceLowerCaseIfAllowed(tab, newTabPath, settings);
            }
            return(newTabPath);
        }
        public void RemovedPageIndexCallBack(string k, object v, CacheItemRemovedReason r)
        {
            cacheItemRemovedReason = r;
#if (DEBUG)
            if (LogRemovedReason)
            {
                var log = new LogInfo {
                    LogTypeKey = "HOST_ALERT"
                };

                string        itemName;
                string        count;
                List <string> portalCounts = null;
                switch (k)
                {
                case "DNN_" + PageIndexKey:
                    itemName = "Page Index";
                    //user profile actions
                    try
                    {
                        DataCache.RemoveCache(UserProfileActionsKey);
                    }
                    catch (ConfigurationErrorsException)
                    {
                        //do nothing, this means the web.config file was overwritten, and thus the cache
                        //was cleared.
                    }
                    if (v != null && v.GetType() == typeof(SharedDictionary <string, string>))
                    {
                        count = "Item Count: " + ((SharedDictionary <string, string>)v).Values.Count.ToString();
                    }
                    else
                    {
                        count = "N/a";
                    }

                    break;

                case "DNN_" + UrlDictKey:
                    itemName = "Friendly Url List";
                    if (v != null &&
                        v.GetType() == typeof(SharedDictionary <int, SharedDictionary <string, string> >))
                    {
                        var friendlyUrls = (SharedDictionary <int, SharedDictionary <string, string> >)v;
                        portalCounts = new List <string>();
                        using (friendlyUrls.GetReadLock())
                        {
                            count = "Portal Count: " + friendlyUrls.Count.ToString();
                            foreach (int key in friendlyUrls.Keys)
                            {
                                SharedDictionary <string, string> portalUrls = friendlyUrls[key];
                                using (portalUrls.GetReadLock())
                                {
                                    portalCounts.Add("Portal " + key.ToString() + " Item Count :" + portalUrls.Count.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        count = "N/a";
                    }
                    break;

                default:
                    itemName = "Url Rewriter Cache Item";
                    count    = "";
                    break;
                }
                //add log values
                log.AddProperty("Url Rewriting Caching Message", itemName + " Cache item Removed.");
                log.AddProperty("Reason", cacheItemRemovedReason.ToString());
                log.AddProperty("Cache Item Key", k);
                log.AddProperty("Item Count", count);
                if (portalCounts != null)
                {
                    int i = 0;
                    foreach (string item in portalCounts)
                    {
                        log.AddProperty("Item " + i.ToString(), item);
                        i++;
                    }
                }
                //System.Diagnostics.Trace.Assert(k != null, "k == " + k);
                LogController.Instance.AddLog(log);
            }
#endif
        }
Example #10
0
        private static bool CheckTabPath(string tabKeyVal, UrlAction result, FriendlyUrlSettings settings, SharedDictionary<string, string> tabDict, ref string newUrl)
        {
            bool found;
            string userParam = String.Empty;
            string tabLookUpKey = tabKeyVal;
            using (tabDict.GetReadLock())
            {
                found = tabDict.ContainsKey(tabLookUpKey); //lookup the tabpath in the tab dictionary
            }

            //special case, if no extensions and the last part of the tabKeyVal contains default.aspx, then
            //split off the default.aspx part and try again - compensating for gemini issue http://support.dotnetnuke.com/issue/ViewIssue.aspx?id=8651&PROJID=39
            if (!found && settings.PageExtensionUsageType != PageExtensionUsageType.AlwaysUse)
            {
                found = CheckSpecialCase(tabLookUpKey, tabDict);
            }

            //Check for VanityUrl
            var doNotRedirectRegex = new Regex(settings.DoNotRedirectRegex);
            if (!found && !AdvancedUrlRewriter.ServiceApi.IsMatch(result.RawUrl) && !doNotRedirectRegex.IsMatch(result.RawUrl))
            {
                string[] urlParams = tabLookUpKey.Split(new[] { "::" }, StringSplitOptions.None);
                if (urlParams.Length > 1)
                {
                    //Extract the first Url parameter
                    string tabPath = urlParams[1];

                    var urlSegments = tabPath.Split('/');

                    string prefix = urlSegments[0];

                    if (prefix == settings.VanityUrlPrefix && urlSegments.Length == 2)
                    {
                        string vanityUrl = urlSegments[1];

                        //check if its a vanityUrl
                        var user = GetUser(result.PortalId, vanityUrl);
                        if (user != null)
                        {
                            userParam = "UserId=" + user.UserID.ToString();

                            //Get the User profile Tab
                            var portal = new PortalController().GetPortal(result.PortalId);
                            var profilePage = new TabController().GetTab(portal.UserTabId, result.PortalId, false);

                            FriendlyUrlOptions options = UrlRewriterUtils.GetOptionsFromSettings(settings);
                            string profilePagePath = TabPathHelper.GetFriendlyUrlTabPath(profilePage, options, Guid.NewGuid());

                            //modify lookup key;
                            tabLookUpKey = tabLookUpKey.Replace("::" + String.Format("{0}/{1}", settings.VanityUrlPrefix, vanityUrl), "::" + profilePagePath.TrimStart('/').ToLowerInvariant());

                            using (tabDict.GetReadLock())
                            {
                                found = tabDict.ContainsKey(tabLookUpKey); //lookup the tabpath in the tab dictionary
                            }
                        }
                    }
                }
            }

            if (found)
            {
                using (tabDict.GetReadLock())
                {
                    //determine what the rewritten URl will be 
                    newUrl = tabDict[tabLookUpKey];
                }
                if (!String.IsNullOrEmpty(userParam))
                {
                    newUrl = newUrl + "&" + userParam;
                }
                //if this is a match on the trigger dictionary rebuild,
                //then temporarily store this value in case it's a page name change
                //677 : only match if is on actual tabKeyVal match, to prevent site root redirects
                //statements were moved into this 'if' statement
                result.dictVal = newUrl;
                result.dictKey = tabKeyVal;
            }
            return found;
        }
Example #11
0
 private static bool CheckSpecialCase(string tabKeyVal, SharedDictionary<string, string> tabDict)
 {
     bool found = false;
     int pathStart = tabKeyVal.LastIndexOf("::", StringComparison.Ordinal); //look for portal alias separator
     int lastPath = tabKeyVal.LastIndexOf('/');
     //get any path separator in the tab path portion
     if (pathStart > lastPath)
     {
         lastPath = pathStart;
     }
     if (lastPath >= 0)
     {
         int defaultStart = tabKeyVal.ToLower().IndexOf("default", lastPath, StringComparison.Ordinal);
         //no .aspx on the end anymore
         if (defaultStart > 0 && defaultStart > lastPath)
         //there is a default in the path, and it's not the entire path (ie pagnamedefault and not default)
         {
             tabKeyVal = tabKeyVal.Substring(0, defaultStart);
             //get rid of the default.aspx part
             using (tabDict.GetReadLock())
             {
                 found = tabDict.ContainsKey(tabKeyVal);
                 //lookup the tabpath in the tab dictionary again
             }
         }
     }
     return found;
 }
Example #12
0
        private static string CheckIfPortalAlias(string url, NameValueCollection querystringCol, UrlAction result, FriendlyUrlSettings settings, SharedDictionary<string, string> tabDict)
        {
            string newUrl = url;
            bool reWritten = false;

            string defaultPage = Globals.glbDefaultPage.ToLower();
            string portalAliasUrl = url.ToLower().Replace("/" + defaultPage, "");
            //if there is a straight match on a portal alias, it's the home page for that portal requested 
            var portalAlias = PortalAliasController.GetPortalAliasInfo(portalAliasUrl);
            if (portalAlias != null)
            {
                //special case : sometimes, some servers issue root/default.aspx when root/ was requested, sometimes not.  It depends
                //on other server software installed (apparently)
                //so check the raw Url and the url, and see if they are the same except for the /default.aspx
                string rawUrl = result.RawUrl;
                if (url.ToLower().EndsWith(rawUrl + defaultPage.ToLower()))
                {
                    //special case - change the url to be equal to the raw Url
                    url = url.Substring(0, url.Length - defaultPage.Length);
                }

                if (settings.RedirectDefaultPage
                    && url.ToLower().EndsWith("/" + defaultPage)
                    && result.RedirectAllowed)
                {
                    result.Reason = RedirectReason.Site_Root_Home;
                    result.FinalUrl = Globals.AddHTTP(portalAliasUrl + "/");
                    result.Action = ActionType.Redirect301;
                }
                else
                {
                    //special case -> look in the tabdict for a blank intercept
                    //735 : switch to custom method for getting portal
                    PortalInfo portal = CacheController.GetPortal(portalAlias.PortalID, true);
                    if (portal.HomeTabId == -1)
                    {
                        string tabKey = url;
                        if (tabKey.EndsWith("/"))
                        {
                            tabKey = tabKey.TrimEnd('/');
                        }
                        tabKey += "::";
                        using (tabDict.GetReadLock())
                        {
                            if (tabDict.ContainsKey(tabKey))
                            {
                                newUrl = tabDict[tabKey];
                                reWritten = true;
                            }
                        }
                        //if no home tab, but matched a portal alias, and no trailing /default.aspx
                        //and no 'newUrl' value because not rewritten, then append the /default.aspx 
                        //and ask for a rewrite on that one.
                        //DNNDEV-27291
                        if (reWritten == false)
                        {
                            newUrl = "/" + DotNetNuke.Common.Globals.glbDefaultPage;
                            reWritten = true;
                        }
                    }
                    else
                    {
                        //set rewrite to home page of site
                        //760: check for portal alias specific culture before choosing home tabid
                        bool checkForCustomAlias = false;
                        bool customTabAlias = false;
                        //check for culture-specific aliases
                        string culture = null;
                        var primaryAliases = TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(portal.PortalID).ToList();
                        //if there are chosen portal aliases, check to see if the found alias is one of them
                        //if not, then will check for a custom alias per tab
                        if (primaryAliases.ContainsAlias(portal.PortalID, portalAlias.HTTPAlias) == false)
                        {
                            checkForCustomAlias = true;
                        }
                        else
                        {
                            //check for a specific culture for the alias
                            culture = primaryAliases.GetCultureByPortalIdAndAlias(portal.PortalID, portalAlias.HTTPAlias);
                        }
                        if (checkForCustomAlias)
                        {
                            //ok, this isnt' a chosen portal alias, check the list of custom aliases
                            List<string> customAliasesForTabs = TabIndexController.GetCustomPortalAliases(settings);
                            if (customAliasesForTabs != null && customAliasesForTabs.Contains(portalAlias.HTTPAlias.ToLower()))
                            {
                                //ok, the alias is used as a custom tab, so now look in the dictionary to see if it's used a 'root' context
                                string tabKey = url.ToLower();
                                if (tabKey.EndsWith("/"))
                                {
                                    tabKey = tabKey.TrimEnd('/');
                                }
                                if (tabKey.EndsWith("/default.aspx"))
                                {
                                    tabKey = tabKey.Substring(0, tabKey.Length - 13); //13 = "/default.aspx".length
                                }
                                tabKey += "::";
                                using (tabDict.GetReadLock())
                                {
                                    if (tabDict.ContainsKey(tabKey))
                                    {
                                        newUrl = tabDict[tabKey];
                                        reWritten = true;
                                        customTabAlias = true; //this alias is used as the alias for a custom tab
                                    }
                                }
                            }
                        }
                        if (customTabAlias == false)
                        {
                            int tabId;
                            if (!String.IsNullOrEmpty(querystringCol["TabId"]))
                            {
                                tabId = Convert.ToInt32(querystringCol["TabId"]);
                                result.Action = ActionType.CheckFor301;
                            }
                            else
                            {
                                tabId = portal.HomeTabId;
                                //not a custom alias for a specific tab, so it must be the home page for the portal we identified
                                if (culture == null)
                                {
                                    culture = portal.DefaultLanguage; //set culture to default if not found specifically
                                }
                                else
                                {
                                    //if there is a specific culture for this alias, and it's different to the default language, then
                                    //go check for a specific culture home page (5.5 and later)
                                    tabId = TabPathHelper.GetHomePageTabIdForCulture(portal.DefaultLanguage,
                                                                                         portal.PortalID,
                                                                                         culture,
                                                                                         tabId);
                                }
                            }
                            //see if there is a skin for the alias/culture combination
                            string skin = TabPathHelper.GetTabAliasSkinForTabAndAlias(portalAlias.PortalID,
                                                                                      portalAlias.HTTPAlias, culture);
                            if (string.IsNullOrEmpty(skin) == false)
                            {
                                newUrl = Globals.glbDefaultPage + TabIndexController.CreateRewritePath(tabId, "", "skinSrc=" + skin);
                            }
                            else
                            {
                                newUrl = Globals.glbDefaultPage + TabIndexController.CreateRewritePath(tabId, "");
                            }
                            if (culture != portal.DefaultLanguage)
                            {
                                AddLanguageCodeToRewritePath(ref newUrl, culture);
                            }
                            //add on language specified by current portal alias
                            reWritten = true;
                        }
                    }
                }

                if (reWritten)
                {
                    //check for replaced to site root from /default.aspx 
                    // 838  set redirect reason and action from result
                    SetRewriteParameters(ref result, newUrl);
                    ActionType action;
                    RedirectReason reason;
                    string resultingUrl;
                    RedirectTokens.DetermineRedirectReasonAndAction(newUrl, result, true, settings, out resultingUrl, out reason, out action);
                    newUrl = resultingUrl;
                    result.Action = action;
                    result.Reason = reason;
                }
            }
            return newUrl;
        }
Example #13
0
        internal void StorePageIndexInCache(SharedDictionary<string, string> tabDictionary,
                                             SharedDictionary<int, PathSizes> portalDepthInfo,
                                             FriendlyUrlSettings settings,
                                             string reason)
        {
            onRemovePageIndex = settings.LogCacheMessages ? (CacheItemRemovedCallback) RemovedPageIndexCallBack : null;

            //get list of portal ids for the portals we are storing in the page index
            var portalIds = new List<int>();
            using (portalDepthInfo.GetReadLock())
            {
                portalIds.AddRange(portalDepthInfo.Keys);
            }

            //783 : use cache dependency to manage page index instead of triggerDictionaryRebuild regex.
            SetPageCache(PageIndexKey, tabDictionary, new DNNCacheDependency(GetTabsCacheDependency(portalIds)), settings, onRemovePageIndex);

            SetPageCache(PageIndexDepthKey, portalDepthInfo, settings);

            LogRemovedReason = settings.LogCacheMessages;

            if (settings.LogCacheMessages)
            {
                var elc = new EventLogController();
                var logValue = new LogInfo {LogTypeKey = "HOST_ALERT"};

                logValue.AddProperty("Url Rewriting Caching Message", "Page Index built and Stored in Cache");
                logValue.AddProperty("Reason", reason);
                logValue.AddProperty("Cache Item Key", PageIndexKey);
                using (tabDictionary.GetReadLock())
                {
                    logValue.AddProperty("Item Count", tabDictionary.Count.ToString());
                }
                logValue.AddProperty("Thread Id", Thread.CurrentThread.ManagedThreadId.ToString());
                elc.AddLog(logValue);
            }
        }
Example #14
0
        /// <summary>
        /// Store the Url Dictionary (all tab urls / tabids) for the installation
        /// </summary>
        /// <param name="urlDict"></param>
        /// <param name="urlPortals"></param>
        /// <param name="customAliasTabs"></param>
        /// <param name="settings"></param>
        /// <param name="reason"></param>
        /// <remarks>
        /// </remarks>
        internal void StoreFriendlyUrlIndexInCache(SharedDictionary<int, SharedDictionary<string, string>> urlDict,
                                                List<int> urlPortals,
                                                SharedDictionary<string, string> customAliasTabs,
                                                FriendlyUrlSettings settings,
                                                string reason)
        {
            if (settings.LogCacheMessages)
            {
                onRemovePageIndex = RemovedPageIndexCallBack;
            }
            else
            {
                onRemovePageIndex = null;
            }

            LogRemovedReason = settings.LogCacheMessages;

            SetPageCache(UrlDictKey, urlDict, new DNNCacheDependency(GetTabsCacheDependency(urlPortals)), settings, onRemovePageIndex);

            SetPageCache(UrlPortalsKey, urlPortals, settings);
            SetPageCache(CustomAliasTabsKey, customAliasTabs, settings);

            if (settings.LogCacheMessages)
            {
                var elc = new EventLogController();

                var logValue = new LogInfo { LogTypeKey = "HOST_ALERT" };
                logValue.AddProperty("Url Rewriting Caching Message", "Friendly Url Index built and Stored in Cache.");
                logValue.AddProperty("Build Reason", reason);
                logValue.AddProperty("Cache Key", UrlDictKey);
                using (urlDict.GetReadLock())
                {
                    logValue.AddProperty("Item Count", urlDict.Values.Count.ToString());
                }
                logValue.AddProperty("Thread Id", Thread.CurrentThread.ManagedThreadId.ToString());
                logValue.AddProperty("Item added to cache", "Url Portals object added to cache.  Key:" + UrlPortalsKey + "  Items: " + urlPortals.Count.ToString());
                logValue.AddProperty("Item added to cache", "Custom Alias Tabs added to cache.  Key:" + CustomAliasTabsKey + " Items: " + customAliasTabs.Count.ToString());
                elc.AddLog(logValue);
            }
        }
 private static bool ResourceFileMayExist(SharedDictionary<string, bool> resourceFileExistsLookup, string cacheKey)
 {
     bool mayExist;
     using (resourceFileExistsLookup.GetReadLock())
     {
         mayExist = !resourceFileExistsLookup.ContainsKey(cacheKey) || resourceFileExistsLookup[cacheKey];
     }
     return mayExist;
 }