Example #1
0
        public static MvcHtmlString GenerateMetaTag(this HtmlHelper helper, string keyword, string description, bool allowIndexPage, bool allowFollowLinks, string author = "", string lastModified = "", string expires = "never", string language = "fa", CacheControlType cacheControlType = CacheControlType.Private)
        {
            //const int maxLengthTitle = 60;
            const int maxLengthDescription = 170;

            //const string favIconPath = "~/cdn/ui/favicon.ico";
            //title = title.Substring(0, title.Length <= maxLengthTitle ? title.Length : maxLengthTitle).Trim();
            description = description.Substring(0, description.Length <= maxLengthDescription ? description.Length : maxLengthDescription).Trim();

            var meta = "";

            //meta += String.Format("<title>{0}</title>\n", title);
            //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=\"keyword\" content=\"{0}\"/>\n", keyword);
            meta += String.Format("<meta name=\"description\" content=\"{0}\"/>\n", description);
            meta += String.Format("<meta http-equiv=\"Cache-control\" content=\"{0}\"/>\n", cacheControlType.GetDescription());
            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(new MvcHtmlString(meta));
        }