public static string GenerateMetaTag(string title, string description, string canonicalUrl, string googlePlusUrl, bool allowIndexPage, bool allowCache, bool allowFollowLinks, string author = "", string lastmodified = "", string expires = "never", string applicationName = "web app", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private, bool allowTranslate = true) { title = title.Substring(0, title.Length <= MaxLenghtTitle ? title.Length : MaxLenghtTitle).Trim(); description = description.Substring(0, description.Length <= MaxLenghtDescription ? description.Length : MaxLenghtDescription).Trim(); var meta = ""; meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += $"<title>{title}</title>\n"; meta += string.Format( "<meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\" name=\"viewport\">"); if (!string.IsNullOrEmpty(googlePlusUrl)) { meta += $"<link rel=\"author\" href=\"{googlePlusUrl}\"/>\n"; } meta += $"<link rel=\"canonical\" href=\"{canonicalUrl}\"/>\n"; meta += $"<link rel=\"shortcut icon\" href=\"{FaviconPath}\" type=\"image/x-icon\" />\n"; meta += $"<meta name=\"application-name\" content=\"{applicationName}\" />\n"; meta += string.Format("<meta name=\"msapplication-config\" content=\"/browserconfig.xml\" />\n"); meta += $"<meta http-equiv=\"content-language\" content=\"{language}\"/>\n"; if (allowTranslate) { meta += string.Format("<meta name=\"google\" content=\"notranslate\" />\n"); } meta += $"<meta name=\"description\" content=\"{description}\"/>\n"; meta += $"<meta http-equiv=\"Cache-control\" content=\"{EnumHelper.GetEnumDescription(typeof (CacheControlType), cacheControlType.ToString())}\"/>\n"; meta += $"<meta name=\"robots\" content=\"{(allowIndexPage ? "index" : "noindex")}, {(allowFollowLinks ? "follow" : "nofollow")}, {(allowCache ? "archive" : "noarchive")}\" />\n"; meta += $"<meta name=\"expires\" content=\"{expires}\"/>\n"; if (!string.IsNullOrEmpty(lastmodified)) { meta += $"<meta name=\"last-modified\" content=\"{lastmodified}\"/>\n"; } if (!string.IsNullOrEmpty(author)) { meta += $"<meta name=\"author\" content=\"{author}\"/>\n"; } //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return(meta); }
public static string GenerateMetaTag(string title, string description, string canonicalUrl, string googlePlusUrl, bool allowIndexPage, bool allowCache, bool allowFollowLinks, string author = "", string lastmodified = "", string expires = "never", string applicationName = "web app", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private, bool allowTranslate = true) { title = title.Substring(0, title.Length <= MaxLenghtTitle ? title.Length : MaxLenghtTitle).Trim(); description = description.Substring(0, description.Length <= MaxLenghtDescription ? description.Length : MaxLenghtDescription).Trim(); var meta = ""; meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += string.Format("<title>{0}</title>\n", title); meta += string.Format( "<meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\" name=\"viewport\">"); if (!string.IsNullOrEmpty(googlePlusUrl)) meta += string.Format("<link rel=\"author\" href=\"{0}\"/>\n", googlePlusUrl); meta += string.Format("<link rel=\"canonical\" href=\"{0}\"/>\n", canonicalUrl); meta += string.Format("<link rel=\"shortcut icon\" href=\"{0}\" type=\"image/x-icon\" />\n", FaviconPath); meta += string.Format("<meta name=\"application-name\" content=\"{0}\" />\n", applicationName); meta += string.Format("<meta name=\"msapplication-config\" content=\"/browserconfig.xml\" />\n"); meta += string.Format("<meta http-equiv=\"content-language\" content=\"{0}\"/>\n", language); if (allowTranslate) meta += string.Format("<meta name=\"google\" content=\"notranslate\" />\n"); meta += string.Format("<meta name=\"description\" content=\"{0}\"/>\n", description); meta += string.Format("<meta http-equiv=\"Cache-control\" content=\"{0}\"/>\n", EnumHelper.GetEnumDescription(typeof(CacheControlType), cacheControlType.ToString())); meta += string.Format("<meta name=\"robots\" content=\"{0}, {1}, {2}\" />\n", allowIndexPage ? "index" : "noindex", allowFollowLinks ? "follow" : "nofollow", allowCache ? "archive" : "noarchive"); meta += string.Format("<meta name=\"expires\" content=\"{0}\"/>\n", expires); if (!string.IsNullOrEmpty(lastmodified)) meta += string.Format("<meta name=\"last-modified\" content=\"{0}\"/>\n", lastmodified); if (!string.IsNullOrEmpty(author)) meta += string.Format("<meta name=\"author\" content=\"{0}\"/>\n", author); //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return meta; }
public static string GenerateMetaTag(string title, string description, bool allowIndexPage, bool allowFollowLinks, string author = "", string lastmodified = "", string expires = "never", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private) { title = title.Substring(0, title.Length <= MaxLenghtTitle ? title.Length : MaxLenghtTitle).Trim(); description = description.Substring(0, description.Length <= MaxLenghtDescription ? description.Length : MaxLenghtDescription).Trim(); var meta = ""; meta += string.Format("<title>{0}</title>\n", title); meta += string.Format("<link rel=\"shortcut icon\" href=\"{0}\"/>\n", FaviconPath); meta += string.Format("<meta http-equiv=\"content-language\" content=\"{0}\"/>\n", language); meta += string.Format("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"); meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += string.Format("<meta name=\"description\" content=\"{0}\"/>\n", description); meta += string.Format("<meta http-equiv=\"Cache-control\" content=\"{0}\"/>\n", EnumHelper.GetEnumDescription(typeof(CacheControlType), cacheControlType.ToString())); meta += string.Format("<meta name=\"robots\" content=\"{0}, {1}\" />\n", allowIndexPage ? "index" : "noindex", allowFollowLinks ? "follow" : "nofollow"); meta += string.Format("<meta name=\"expires\" content=\"{0}\"/>\n", expires); if (!string.IsNullOrEmpty(lastmodified)) { meta += string.Format("<meta name=\"last-modified\" content=\"{0}\"/>\n", lastmodified); } if (!string.IsNullOrEmpty(author)) { meta += string.Format("<meta name=\"author\" content=\"{0}\"/>\n", author); } //------------------------------------Google & Bing Doesn't Use Meta Keywords ... //meta += string.Format("<meta name=\"keywords\" content=\"{0}\"/>\n", keywords); return(meta); }