private bool ShouldBeActive() { if (!String.IsNullOrWhiteSpace(AspPage)) { string currentPage = ViewContext.RouteData.Values["page"].ToString().ToLowerInvariant(); AspPage = AspPage.Trim().ToLowerInvariant(); var regexPattern = "^" + AspPage + "$"; if (IsRegexPatternValid(regexPattern)) { Regex rgx = new Regex(regexPattern); if (rgx.IsMatch(currentPage)) { return(true); } } } else if (!String.IsNullOrWhiteSpace(Href)) { string currentUrl = ViewContext.HttpContext.Request.Path.ToString().ToLowerInvariant(); if (currentUrl == Href) { return(true); } } return(false); }
private bool ShouldBeActive() { if (!String.IsNullOrWhiteSpace(AspPage)) { string currentPage = ViewContext.RouteData.Values["page"].ToString().ToLowerInvariant(); //AspPage should be processed and if it ends on index this should be removed AspPage = AspPage.Trim().ToLowerInvariant(); //if (AspPage.EndsWith("/index")) { // AspPage = AspPage.Substring(0, AspPage.Length - 6); //} var pathNodeList = AspPage.Split("/").ToList(); pathNodeList.RemoveAt(pathNodeList.Count - 1); AspPage = String.Join("/", pathNodeList.ToArray()); var regexPattern = "^" + AspPage; if (IsRegexPatternValid(regexPattern)) { Regex rgx = new Regex(regexPattern); if (rgx.IsMatch(currentPage)) { return(true); } } } else if (!String.IsNullOrWhiteSpace(Href)) { string currentUrl = ViewContext.HttpContext.Request.Path.ToString().ToLowerInvariant(); var regexPattern = "^" + Href; if (IsRegexPatternValid(regexPattern)) { Regex rgx = new Regex(regexPattern); if (rgx.IsMatch(currentUrl)) { return(true); } } } return(false); }