Satrabel.OpenUrlRewriter.Components.CacheController.GetRewriteTabRule C# (CSharp) Метод

GetRewriteTabRule() публичный Метод

public GetRewriteTabRule ( string CultureCode, int TabId ) : Satrabel.HttpModules.Provider.UrlRule
CultureCode string
TabId int
Результат Satrabel.HttpModules.Provider.UrlRule
        public UrlRule GetRewriteTabRule(string CultureCode, int TabId)
        {
            var rules = _rules.Where(r => r.RuleType == UrlRuleType.Tab && r.Action == UrlRuleAction.Rewrite && r.TabId == TabId);
            var rule = GetFirstRule(rules, CultureCode);
            return rule;
        }

Usage Example

        private static bool CheckTabIdRedirect(string ApplicationPath, Uri Url, PortalAliasInfo objPortalAlias, RewriterAction action, CacheController cacheCtrl)
        {
            bool RuleMatch = false;
            if (cacheCtrl != null && action.LocalPath.ToLower().Contains("tabid")) // for performance
            {
                // check for tabid in the url (OpenUrlRewriter use for public urls, the pagename after the language in the url)
                string pattern = "^" + RewriterUtils.ResolveUrl(ApplicationPath, "[^?]*/TabId/(\\d+)(.*)") + "$";
                Match objMatch = Regex.Match(Url.LocalPath, pattern, RegexOptions.IgnoreCase);
                //if there is a match
                if (objMatch.Success)
                {
                    action.TabId = int.Parse(objMatch.Groups[1].Value);
                    // if there is a rule for the tabid, the OpenUrlRewriter manage the rewriter otherwise the SiteUrls rules discard all processing
                    var rule = cacheCtrl.GetRewriteTabRule(action.CultureCode, action.TabId);
                    if (rule == null && objPortalAlias != null)
                    // if rule not found maybe because culture missing in url
                    {
                        TabController tc = new TabController();
                        var tab = tc.GetTab(action.TabId, objPortalAlias.PortalID, false);
                        if (tab != null)
                        {
                            action.CultureCode = tab.CultureCode;
            #if DNN71
                            var primaryAliases = DotNetNuke.Entities.Portals.Internal.TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(objPortalAlias.PortalID).ToList();
                            var alias = primaryAliases.FirstOrDefault(a => a.CultureCode == action.CultureCode);
                            if (alias != null)
                            {
                                action.Alias = alias.HTTPAlias;
                            }
            #endif
                            rule = cacheCtrl.GetRewriteTabRule(action.CultureCode, action.TabId);
                        }
                    }
                    if (rule != null)
                    {
                        // construct the standard dnn path format /alias/culture/pageurl/parameters
            #if DNN71
                        string langParms = "";
            #else
                        string langParms = string.IsNullOrEmpty(action.CultureCode) ? "" : "/" + action.CultureCode;
            #endif

                        action.LocalPath = RewriterUtils.ResolveUrl(ApplicationPath, Regex.Replace(action.LocalPath, pattern, "~" + langParms + "/" + rule.Url + "$2", RegexOptions.IgnoreCase));
                        action.WorkUrl = RewriterUtils.ResolveUrl(ApplicationPath, Regex.Replace(action.WorkUrl, pattern, "~" + langParms + "/" + rule.Url + "$2", RegexOptions.IgnoreCase));
                        //action.RedirectUrl = action.HostPort + action.LocalPath;
                        action.DoRedirect = true;
                        action.Raison += "+tabid present";
                        action.RedirectPage = rule.Url;
                        RuleMatch = true;
                    }
                    //  ~/Default.aspx?TabId=$1
                }
            }
            else if (cacheCtrl != null && action.QueryUrl.ToLower().Contains("tabid") && action.LocalPath.ToLower().Contains("default.aspx")) // for performance
            {
                // check for tabid in the url (OpenUrlRewriter use for public urls, the pagename after the language in the url)
                string pattern = "^" + RewriterUtils.ResolveUrl(ApplicationPath, "[?&]TabId=(\\d+)(.*)") + "$";
                Match objMatch = Regex.Match(action.QueryUrl, pattern, RegexOptions.IgnoreCase);
                //if there is a match
                if (objMatch.Success)
                {

                    action.TabId = int.Parse(objMatch.Groups[1].Value);
                    // if there is a rule for the tabid, the OpenUrlRewriter manage the rewriter otherwise the SiteUrls rules discard all processing
                    var rule = cacheCtrl.GetRewriteTabRule(action.CultureCode, action.TabId);
                    if (rule == null && objPortalAlias != null)
                    // if rule not found maybe because culture missing in url
                    {
                        TabController tc = new TabController();
                        var tab = tc.GetTab(action.TabId, objPortalAlias.PortalID, false);
                        if (tab != null)
                        {
                            action.CultureCode = tab.CultureCode;

            #if DNN71
                            var primaryAliases = DotNetNuke.Entities.Portals.Internal.TestablePortalAliasController.Instance.GetPortalAliasesByPortalId(objPortalAlias.PortalID).ToList();
                            var alias = primaryAliases.FirstOrDefault(a => a.CultureCode == action.CultureCode);
                            if (alias != null)
                            {
                                action.Alias = alias.HTTPAlias;
                            }
            #endif

                            rule = cacheCtrl.GetRewriteTabRule(action.CultureCode, action.TabId);
                        }
                    }
                    if (rule != null)
                    {
                        // construct the standard dnn path format /alias/culture/pageurl/parameters

                        action.QueryUrl = Regex.Replace(action.QueryUrl, pattern, "$2", RegexOptions.IgnoreCase);
            #if DNN71
                        string langParms = "";
            #else
                        string langParms = string.IsNullOrEmpty(action.CultureCode) ? "" : "/" + action.CultureCode;
            #endif
                        if (string.IsNullOrEmpty(action.LocalPath) || action.LocalPath == "/")
                        {
                            action.LocalPath = RewriterUtils.ResolveUrl(ApplicationPath, "~" + langParms + "/" + rule.Url);
                            action.WorkUrl = RewriterUtils.ResolveUrl(ApplicationPath, "~" + langParms + "/" + rule.Url);
                        }
                        //action.RedirectUrl = action.HostPort + action.LocalPath;

                        action.DoRedirect = true;
                        action.Raison += "+tabid present";
                        action.RedirectPage = rule.Url;
                        RuleMatch = true;

                    }

                    //  ~/Default.aspx?TabId=$1
                }
            }
            else if (cacheCtrl != null && action.QueryUrl.ToLower().Contains("tabid") && action.QueryUrl.ToLower().Contains("passwordreset")) // for performance
            {

                string pattern = "^" + RewriterUtils.ResolveUrl(ApplicationPath, "[?&]TabId=(\\d+)(.*)") + "$";
                Match objMatch = Regex.Match(action.QueryUrl, pattern, RegexOptions.IgnoreCase);
                //if there is a match
                if (objMatch.Success)
                {

                        action.QueryUrl = Regex.Replace(action.QueryUrl, pattern, "$2", RegexOptions.IgnoreCase);

                }
            }

            return RuleMatch;
        }