Example #1
0
        public SeoMetaTags GetMetaTags()
        {
            if (!File.Exists(MetaConfigFile))
            {
                return(null);
            }

            SeoMetaTags seoMetaTags = new SeoMetaTags();

            using (XmlReader reader = XmlReader.Create(MetaConfigFile))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                        case "MetaDescription":
                            seoMetaTags.MetaDescription = reader.ReadString();
                            break;

                        case "MetaKeywords":
                            seoMetaTags.MetaKeywords = reader.ReadString();
                            break;

                        case "TwitterCard":
                            seoMetaTags.TwitterCard = reader.ReadString();
                            break;

                        case "TwitterSite":
                            seoMetaTags.TwitterSite = reader.ReadString();
                            break;

                        case "TwitterCreator":
                            seoMetaTags.TwitterCreator = reader.ReadString();
                            break;

                        case "TwitterImage":
                            seoMetaTags.TwitterImage = reader.ReadString();
                            break;

                        case "FaceBookAdmins":
                            seoMetaTags.FaceBookAdmins = reader.ReadString();
                            break;

                        case "FaceBookAppID":
                            seoMetaTags.FaceBookAppID = reader.ReadString();
                            break;
                        }
                    }
                }
            }
            return(seoMetaTags);
        }
Example #2
0
        public static string CreateSeoMetaInformation(EntryCollection weblogEntries, IBlogDataService dataService)
        {
            string metaTags = "\r\n";
            string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;

            if (currentUrl.IndexOf("categoryview.aspx", StringComparison.OrdinalIgnoreCase) > -1 || currentUrl.IndexOf("default.aspx?month=", StringComparison.OrdinalIgnoreCase) > -1)
            {
                metaTags += MetaNoindexFollowPattern;
            }
            else if (currentUrl.IndexOf("permalink.aspx", StringComparison.OrdinalIgnoreCase) > -1)
            {
                if (weblogEntries.Count >= 1)
                {
                    Entry entry = weblogEntries[0];
                    metaTags = GetMetaTags(metaTags, entry);
                }
            }
            else if (currentUrl.IndexOf("commentview.aspx", StringComparison.OrdinalIgnoreCase) > -1 && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["guid"]))
            {
                Entry entry = dataService.GetEntry(HttpContext.Current.Request.QueryString["guid"]);
                if (entry != null)
                {
                    metaTags = GetMetaTags(metaTags, entry);
                }
            }
            else if (currentUrl.IndexOf("commentview.aspx", StringComparison.OrdinalIgnoreCase) > -1 && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["title"]))
            {
                Entry entry = dataService.GetEntry(HttpContext.Current.Request.QueryString["title"]);
                if (entry != null)
                {
                    metaTags = GetMetaTags(metaTags, entry);
                }
            }
            else if (currentUrl.IndexOf("default.aspx", StringComparison.OrdinalIgnoreCase) > -1)
            {
                var smt = new SeoMetaTags();
                smt = smt.GetMetaTags();
                if (smt != null)
                {
                    if (!string.IsNullOrEmpty(smt.MetaDescription))
                    {
                        metaTags += string.Format(MetaDescriptionTagPattern, smt.MetaDescription);
                    }

                    if (!string.IsNullOrEmpty(smt.MetaKeywords))
                    {
                        metaTags += string.Format(MetaKeywordTagPattern, smt.MetaKeywords);
                    }
                }
                metaTags += string.Format(CanonicalLinkPattern, SiteUtilities.GetBaseUrl());
            }
            return metaTags;
        }
Example #3
0
        public static string CreateSeoMetaInformation(EntryCollection weblogEntries, IBlogDataService dataService)
        {
            string metaTags   = "\r\n";
            string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;

            if (currentUrl.IndexOf("categoryview.aspx", StringComparison.OrdinalIgnoreCase) > -1 || currentUrl.IndexOf("default.aspx?month=", StringComparison.OrdinalIgnoreCase) > -1)
            {
                metaTags += MetaNoindexFollowPattern;
            }
            else if (currentUrl.IndexOf("permalink.aspx", StringComparison.OrdinalIgnoreCase) > -1)
            {
                if (weblogEntries.Count >= 1)
                {
                    Entry entry = weblogEntries[0];
                    metaTags = GetMetaTags(metaTags, entry);
                }
            }
            else if (currentUrl.IndexOf("commentview.aspx", StringComparison.OrdinalIgnoreCase) > -1 && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["guid"]))
            {
                Entry entry = dataService.GetEntry(HttpContext.Current.Request.QueryString["guid"]);
                if (entry != null)
                {
                    metaTags = GetMetaTags(metaTags, entry);
                }
            }
            else if (currentUrl.IndexOf("commentview.aspx", StringComparison.OrdinalIgnoreCase) > -1 && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["title"]))
            {
                Entry entry = dataService.GetEntry(HttpContext.Current.Request.QueryString["title"]);
                if (entry != null)
                {
                    metaTags = GetMetaTags(metaTags, entry);
                }
            }
            else if (currentUrl.IndexOf("default.aspx", StringComparison.OrdinalIgnoreCase) > -1)
            {
                var smt = new SeoMetaTags();
                smt = smt.GetMetaTags();
                if (smt != null)
                {
                    if (!string.IsNullOrEmpty(smt.MetaDescription))
                    {
                        metaTags += string.Format(MetaDescriptionTagPattern, smt.MetaDescription);
                    }

                    if (!string.IsNullOrEmpty(smt.MetaKeywords))
                    {
                        metaTags += string.Format(MetaKeywordTagPattern, smt.MetaKeywords);
                    }
                }
                metaTags += string.Format(CanonicalLinkPattern, SiteUtilities.GetBaseUrl());
            }
            return(metaTags);
        }
Example #4
0
        public static void Save(SeoMetaTags seoConfig)
        {
            System.Security.Principal.WindowsImpersonationContext wi = Impersonation.Impersonate();

            XmlSerializer ser = new XmlSerializer(typeof(SeoMetaTags));

            using (StreamWriter writer = new StreamWriter(MetaConfigFile))
            {
                ser.Serialize(writer, seoConfig);
            }

            wi.Undo();
        }
Example #5
0
        private SeoMetaTags GetMetaTagsFromConfig()
        {
            if (!File.Exists(MetaConfigFile))
            {
                return null;
            }

            SeoMetaTags seoMetaTags = new SeoMetaTags();

            using (XmlReader reader = XmlReader.Create(MetaConfigFile))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                            case "MetaDescription":
                                seoMetaTags.MetaDescription = reader.ReadString();
                                break;
                            case "MetaKeywords":
                                seoMetaTags.MetaKeywords = reader.ReadString();
                                break;
                            case "TwitterCard":
                                seoMetaTags.TwitterCard = reader.ReadString();
                                break;
                            case "TwitterSite":
                                seoMetaTags.TwitterSite = reader.ReadString();
                                break;
                            case "TwitterCreator":
                                seoMetaTags.TwitterCreator = reader.ReadString();
                                break;
                            case "TwitterImage":
                                seoMetaTags.TwitterImage = reader.ReadString();
                                break;
                            case "FaceBookAdmins":
                                seoMetaTags.FaceBookAdmins = reader.ReadString();
                                break;
                            case "FaceBookAppID":
                                seoMetaTags.FaceBookAppID = reader.ReadString();
                                break;
                        }
                    }
                }
            }
            return seoMetaTags;
        }
Example #6
0
        private static string GetMetaTags(string metaTags, Entry entry)
        {
            // Canonical Tag
            metaTags += string.Format(CanonicalLinkPattern, SiteUtilities.GetPermaLinkUrl(entry));

            // Meta Description
            string blogPostDescription;
            string twitterImage;
            string twitterVideo;

            if (string.IsNullOrEmpty(entry.Description) || entry.Description.Length < 20)
            {
                blogPostDescription = entry.Content;
            }
            else
            {
                blogPostDescription = entry.Description;
            }

            //This is dangerous stuff, don't freak out if it doesn't work.
            try
            {
                twitterImage = FindFirstImage(blogPostDescription);
                twitterVideo = FindFirstYouTubeVideo(blogPostDescription);
            }
            catch(Exception ex)
            {
                Trace.WriteLine("Exception looking for Images and Video: " + ex.ToString());
                twitterImage = string.Empty;
                twitterVideo = string.Empty;
            }
            blogPostDescription = HttpUtility.HtmlDecode(blogPostDescription);
            blogPostDescription = blogPostDescription.RemoveLineBreaks();
            blogPostDescription = blogPostDescription.StripHtml();
            blogPostDescription = blogPostDescription.RemoveDoubleSpaceCharacters();
            blogPostDescription = blogPostDescription.Trim();
            blogPostDescription = blogPostDescription.CutLongString(160);
            blogPostDescription = blogPostDescription.RemoveQuotationMarks();

            var smt = new SeoMetaTags();
            smt = smt.GetMetaTags();

            if (blogPostDescription.Length == 0)
                blogPostDescription = smt.MetaDescription;

            metaTags += string.Format(MetaDescriptionTagPattern, blogPostDescription);

            // Meta Keywords
            if (!string.IsNullOrEmpty(entry.Categories))
            {
                metaTags += string.Format(MetaKeywordTagPattern, entry.Categories.Replace(';', ','));
            }

            //Twitter SEO Integration
            metaTags += string.Format(MetaTwitterCardPattern, smt.TwitterCard);
            metaTags += string.Format(MetaTwitterSitePattern, smt.TwitterSite);
            metaTags += string.Format(MetaTwitterCreatorPattern, smt.TwitterCreator);
            metaTags += string.Format(MetaTwitterTitlePattern, entry.Title);
            metaTags += string.Format(MetaTwitterDescriptionPattern, blogPostDescription.CutLongString(120));

            if (twitterImage.Length > 0)
            {
                metaTags += string.Format(MetaTwitterImagePattern, twitterImage);
            }
            else if(twitterVideo.Length > 0)
            {
                metaTags += string.Format(MetaTwitterImagePattern, twitterVideo);
            }
            else
            {
                metaTags += string.Format(MetaTwitterImagePattern, smt.TwitterImage);
            }

            //FaceBook OG Integration
            metaTags += string.Format(MetaFaceBookUrlPattern, SiteUtilities.GetPermaLinkUrl(entry));
            metaTags += string.Format(MetaFaceBookTitlePattern, entry.Title);

            if (twitterImage.Length > 0)
            {
                metaTags += string.Format(MetaFaceBookImagePattern, twitterImage);
            }
            else if (twitterVideo.Length > 0)
            {
                metaTags += string.Format(MetaFaceBookImagePattern, twitterVideo);
            }
            else
            {
                metaTags += string.Format(MetaFaceBookImagePattern, smt.TwitterImage);
            }

            metaTags += string.Format(MetaFaceBookDescriptionPattern, blogPostDescription.CutLongString(120));
            metaTags += MetaFaceBookTypePattern;
            metaTags += string.Format(MetaFaceBookAdminsPattern, smt.FaceBookAdmins);
            metaTags += string.Format(MetaFaceBookAppIDPattern, smt.FaceBookAppID);

            //Scheme.org meta data integration
            metaTags += MetaSchemeOpenScript;
            metaTags += MetaSchemeContext;
            metaTags += MetaSchemeType;
            metaTags += string.Format(MetaSchemeHeadline, entry.Title);
            metaTags += string.Format(MetaSchemeDatePublished, entry.CreatedUtc.ToString("yyyy-MM-dd"));
            metaTags += string.Format(MetaSchemeDescription, blogPostDescription.CutLongString(240));
            metaTags += string.Format(MetaSchemeUrl, SiteUtilities.GetPermaLinkUrl(entry));
            metaTags += string.Format(MetaSchemeImage, twitterImage);
            metaTags += MetaSchemeCloseScript;

            return metaTags;
        }
Example #7
0
        private static string GetMetaTags(string metaTags, Entry entry)
        {
            // Canonical Tag
            metaTags += string.Format(CanonicalLinkPattern, SiteUtilities.GetPermaLinkUrl(entry));

            // Meta Description
            string blogPostDescription;
            string postImage;
            string postVideo;

            blogPostDescription = entry.Content;

            //This is dangerous stuff, don't freak out if it doesn't work.
            try
            {
                postImage = FindFirstImage(blogPostDescription);
                postVideo = FindFirstYouTubeVideo(blogPostDescription);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception looking for Images and Video: " + ex.ToString());
                postImage = string.Empty;
                postVideo = string.Empty;
            }
            blogPostDescription = HttpUtility.HtmlDecode(blogPostDescription);
            blogPostDescription = blogPostDescription.RemoveLineBreaks();
            blogPostDescription = blogPostDescription.StripHtml();
            blogPostDescription = blogPostDescription.RemoveDoubleSpaceCharacters();
            blogPostDescription = blogPostDescription.Trim();
            blogPostDescription = blogPostDescription.CutLongString(160);
            blogPostDescription = blogPostDescription.RemoveQuotationMarks();

            var smt = new SeoMetaTags();

            smt = smt.GetMetaTags();

            if (blogPostDescription.Length == 0)
            {
                blogPostDescription = smt.MetaDescription;
            }

            metaTags += string.Format(MetaDescriptionTagPattern, blogPostDescription);

            // Meta Keywords
            if (!string.IsNullOrEmpty(entry.Categories))
            {
                metaTags += string.Format(MetaKeywordTagPattern, entry.Categories.Replace(';', ','));
            }

            //Twitter SEO Integration
            metaTags += string.Format(MetaTwitterCardPattern, smt.TwitterCard);
            metaTags += string.Format(MetaTwitterSitePattern, smt.TwitterSite);
            metaTags += string.Format(MetaTwitterCreatorPattern, smt.TwitterCreator);
            metaTags += string.Format(MetaTwitterTitlePattern, entry.Title);
            metaTags += string.Format(MetaTwitterDescriptionPattern, blogPostDescription.CutLongString(120));

            if (postImage.Length > 0)
            {
                metaTags += string.Format(MetaTwitterImagePattern, postImage);
            }
            else if (postVideo.Length > 0)
            {
                metaTags += string.Format(MetaTwitterImagePattern, postVideo);
            }
            else
            {
                metaTags += string.Format(MetaTwitterImagePattern, smt.TwitterImage);
            }

            //FaceBook OG Integration
            metaTags += string.Format(MetaFaceBookUrlPattern, SiteUtilities.GetPermaLinkUrl(entry));
            metaTags += string.Format(MetaFaceBookTitlePattern, entry.Title);

            if (postImage.Length > 0)
            {
                metaTags += string.Format(MetaFaceBookImagePattern, postImage);
            }
            else if (postVideo.Length > 0)
            {
                metaTags += string.Format(MetaFaceBookImagePattern, postVideo);
            }
            else
            {
                metaTags += string.Format(MetaFaceBookImagePattern, smt.TwitterImage);
            }

            metaTags += string.Format(MetaFaceBookDescriptionPattern, blogPostDescription.CutLongString(120));
            metaTags += MetaFaceBookTypePattern;
            metaTags += string.Format(MetaFaceBookAdminsPattern, smt.FaceBookAdmins);
            metaTags += string.Format(MetaFaceBookAppIDPattern, smt.FaceBookAppID);


            //Scheme.org meta data integration
            metaTags += MetaSchemeOpenScript;
            metaTags += MetaSchemeContext;
            metaTags += MetaSchemeType;
            metaTags += string.Format(MetaSchemeHeadline, entry.Title);
            metaTags += string.Format(MetaSchemeDatePublished, entry.CreatedUtc.ToString("yyyy-MM-dd"));
            metaTags += string.Format(MetaSchemeDescription, blogPostDescription.CutLongString(240));
            metaTags += string.Format(MetaSchemeUrl, SiteUtilities.GetPermaLinkUrl(entry));
            metaTags += string.Format(MetaSchemeImage, postImage);
            metaTags += MetaSchemeCloseScript;

            return(metaTags);
        }