/// <summary> /// Checks if the meta tags contain unallowed meta tags. /// </summary> /// <param name="page"></param> private PageValidationResult CheckForbiddenMetaTags(PageValidationResult res) { res.MetaTagsAreValid.Valid = true; //Loop controls foreach (Control header in res.Page.Header.Controls) { Type headerType = header.GetType(); if (headerType == typeof(System.Web.UI.HtmlControls.HtmlMeta)) { System.Web.UI.HtmlControls.HtmlMeta control = (System.Web.UI.HtmlControls.HtmlMeta)header; string TagName = control.Name; if (config.Modules.Yoast.MetaTagIsUnallowed(TagName.ToLower())) { res.MetaTagsAreValid.Valid = false; res.MetaTagsAreValid.Message = TagName + " meta tag found, this is unallowed!"; res.MetaTagsAreValid.CssClass = defaultInvalidCssClass; res.Fail(res.MetaTagsAreValid.Message); return(res); } } else { if (headerType == typeof(System.Web.UI.LiteralControl)) { System.Web.UI.LiteralControl control = (LiteralControl)header; //Match paterns to find out with tokens are used Regex fullNameRegex = new Regex("name=\"(.+?)\""); Regex nameRegex = new Regex("\"(.+?)\""); Regex contentRegex = new Regex("content=\"(.+?)\""); Regex metaTags = new Regex(@"<meta(.+?)>"); foreach (Match metaTag in metaTags.Matches(control.Text)) { string fullName = fullNameRegex.Match(metaTag.Value).Value; string name = nameRegex.Match(fullName).Value; name = name.Replace("\"", ""); string content = contentRegex.Match(metaTag.Value).Value; if (config.Modules.Yoast.MetaTagIsUnallowed(name.ToLower())) { res.MetaTagsAreValid.Valid = false; res.MetaTagsAreValid.Message = name + " meta tag found, this is unallowed!"; res.MetaTagsAreValid.CssClass = defaultInvalidCssClass; res.Fail(res.MetaTagsAreValid.Message); return(res); } } } } } return(res); }
/// <summary> /// Check if keyword is empty /// </summary> private PageValidationResult ValidateKeywordEmpty(PageValidationResult res) { if (String.IsNullOrEmpty(res.Keyword)) { res.Fail("No keyword set"); } return(res); }