C# Dinamik Html Meta Etiketleri Oluşturmak
C# DİNAMİK HTMLMETA ETİKETLERİ VE HTMLLİNK OLUŞTURMAK

CSHARP | Ali Yasin Doğan | 06.02.2019 | 2057

C#'da Dinamik olarak Html Meta ve Html Link Oluşturma ile ilgili Kodları Sizinle Paylaşacağım

Bu kodlarda Sosyal Medya Linklerin JS,CSS dosyalarına kadar tüm metahtml ve meta linkler mevcut. 
Faydalı olması dileğiyle.
Allah cc Emanet Olun.

/*
*Kategori Listesinden Html Meta Etiketleri Çekiyor
*Aşağıdaki using'ler eklenecek
*using System.Web.UI;
*using System.Web.UI.HtmlControls;
*/
        public void HtmlMetaGetir(Kategori _kategori, Page _page)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(conString))
                {
                    using (SqlDataAdapter adp = new SqlDataAdapter("sp_HtmlMetaGetir", con))
                    {
                        adp.SelectCommand.CommandType = CommandType.StoredProcedure;
                        adp.SelectCommand.Parameters.AddWithValue("@KategoriId", _kategori.KategoriId);
                        DataTable dt = new DataTable();
                        adp.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            #region HtmlMetaEtiketleri

                            HtmlTitle title = new HtmlTitle();
                            title.Text = _kategori.Title;
                            _page.Header.Controls.Add(title);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta utf = new HtmlMeta();
                            utf.HttpEquiv = "Content-Type";
                            utf.Content = "text/html; charset=utf-8";
                            _page.Header.Controls.Add(utf);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta desc = new HtmlMeta();
                            desc.Name = "description";
                            desc.Content = _kategori.MetaDesc;
                            _page.Header.Controls.Add(desc);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta key = new HtmlMeta();
                            key.Name = "keywords";
                            key.Content = _kategori.MetaTag;
                            _page.Header.Controls.Add(key);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta copy = new HtmlMeta();
                            copy.Name = "copyright";
                            copy.Content = "Firma © Copyright  2015";
                            _page.Header.Controls.Add(copy);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twittersite = new HtmlMeta();
                            twittersite.Attributes["name"] = "twitter:site";
                            twittersite.Attributes["content"] = "@firma";
                            _page.Header.Controls.Add(twittersite);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twittercard = new HtmlMeta();
                            twittercard.Attributes["name"] = "twitter:card";
                            twittercard.Attributes["content"] = "summary_large_image";
                            _page.Header.Controls.Add(twittercard);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twitterdescription = new HtmlMeta();
                            twitterdescription.Attributes["name"] = "twitter:description";
                            twitterdescription.Attributes["content"] = _kategori.MetaDesc;
                            _page.Header.Controls.Add(twitterdescription);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twitterimage = new HtmlMeta();
                            twitterimage.Attributes["name"] = "twitter:image";
                            twitterimage.Attributes["content"] = _kategori.ResimUrl;
                            _page.Header.Controls.Add(twitterimage);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twittertitle = new HtmlMeta();
                            twittertitle.Attributes["name"] = "twitter:title";
                            twittertitle.Attributes["content"] = _kategori.Title;
                            _page.Header.Controls.Add(twittertitle);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twitterurl = new HtmlMeta();
                            twitterurl.Attributes["name"] = "twitter:url";
                            twitterurl.Attributes["content"] = _kategori.SeoLink;
                            _page.Header.Controls.Add(twitterurl);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta twittercreator = new HtmlMeta();
                            twittercreator.Attributes["name"] = "twitter:creator";
                            twittercreator.Attributes["content"] = "@firma";
                            _page.Header.Controls.Add(twittercreator);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            //Facebook-Google Plus
                            HtmlMeta ogtype = new HtmlMeta();
                            ogtype.Attributes["property"] = "og:type";
                            ogtype.Attributes["content"] = "website";
                            _page.Header.Controls.Add(ogtype);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta ogurl = new HtmlMeta();
                            ogurl.Attributes["property"] = "og:url";
                            ogurl.Attributes["content"] = _kategori.SeoLink;
                            _page.Header.Controls.Add(ogurl);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta ogsitename = new HtmlMeta();
                            ogsitename.Attributes["property"] = "og:site_name";
                            ogsitename.Attributes["content"] = "Firma";
                            _page.Header.Controls.Add(ogsitename);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta ogtitle = new HtmlMeta();
                            ogtitle.Attributes["property"] = "og:title";
                            ogtitle.Attributes["content"] = _kategori.Title;
                            _page.Header.Controls.Add(ogtitle);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta ogdescription = new HtmlMeta();
                            ogdescription.Attributes["property"] = "og:description";
                            ogdescription.Attributes["content"] = _kategori.MetaDesc;
                            _page.Header.Controls.Add(ogdescription);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta ogimage = new HtmlMeta();
                            ogimage.Attributes["property"] = "og:image";
                            ogimage.Attributes["content"] = _kategori.ResimUrl;
                            _page.Header.Controls.Add(ogimage);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta oglocale = new HtmlMeta();
                            oglocale.Attributes["property"] = "og:locale";
                            oglocale.Attributes["content"] = "tr-TR";
                            _page.Header.Controls.Add(oglocale);
                            _page.Header.Controls.Add(new LiteralControl("\n"));


                            HtmlMeta abs = new HtmlMeta();
                            abs.Name = "abstract";
                            abs.Content = "Firma";
                            _page.Header.Controls.Add(abs);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta aut = new HtmlMeta();
                            aut.Name = "author";
                            aut.Content = "Firma © Copyright  2015";
                            _page.Header.Controls.Add(aut);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta clas = new HtmlMeta();
                            clas.Name = "classification";
                            clas.Content = "Yazılım Firması";
                            _page.Header.Controls.Add(clas);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta lang = new HtmlMeta();
                            lang.Name = "content-language";
                            lang.Content = "tr-TR";
                            _page.Header.Controls.Add(lang);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta bot = new HtmlMeta();
                            bot.Name = "googlebot";
                            bot.Content = "all, index, follow";
                            _page.Header.Controls.Add(bot);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta dist = new HtmlMeta();
                            dist.Name = "distribution";
                            dist.Content = "Global";
                            _page.Header.Controls.Add(dist);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta rat = new HtmlMeta();
                            rat.Name = "rating";
                            rat.Content = "All";
                            _page.Header.Controls.Add(rat);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta prag = new HtmlMeta();
                            prag.HttpEquiv = "pragma";
                            prag.Content = "no-cache";
                            _page.Header.Controls.Add(prag);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta reply = new HtmlMeta();
                            reply.HttpEquiv = "reply-to";
                            reply.Content = "info@firma.com.tr";
                            _page.Header.Controls.Add(reply);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta targ = new HtmlMeta();
                            targ.HttpEquiv = "window-target";
                            targ.Content = "_top";
                            _page.Header.Controls.Add(targ);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta edge = new HtmlMeta();
                            edge.HttpEquiv = "X-UA-Compatible";
                            edge.Content = "IE=edge";
                            _page.Header.Controls.Add(edge);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta robot = new HtmlMeta();
                            robot.Name = "robots";
                            robot.Content = "index, follow, imageindex, imageclick, archive";
                            _page.Header.Controls.Add(robot);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta language = new HtmlMeta();
                            language.Name = "language";
                            language.Content = "Turkish";
                            _page.Header.Controls.Add(language);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta viewport = new HtmlMeta();
                            viewport.Name = "viewport";
                            viewport.Content = "width=device-width, initial-scale=1.0";
                            _page.Header.Controls.Add(viewport);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta pinterest = new HtmlMeta();
                            pinterest.Name = "p:domain_verify";
                            pinterest.Content = "654asdhgj7g4h654fgh";
                            _page.Header.Controls.Add(pinterest);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlMeta alexa = new HtmlMeta();
                            alexa.Name = "alexaVerifyID";
                            alexa.Content = "654asdhgj7g4h654fgh";
                            _page.Header.Controls.Add(alexa);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink hreflang = new HtmlLink();
                            hreflang.Attributes["rel"] = "alternate";
                            hreflang.Href = _kategori.SeoLink;
                            hreflang.Attributes["hreflang"] = "tr";
                            _page.Header.Controls.Add(hreflang);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink canonical = new HtmlLink();
                            canonical.Attributes["rel"] = "canonical";
                            canonical.Href = _kategori.SeoLink;
                            _page.Header.Controls.Add(canonical);

                            HtmlLink appleicon57 = new HtmlLink();
                            appleicon57.Attributes["rel"] = "apple-touch-icon";
                            appleicon57.Href = "/images/logo/apple-icon-57x57.png";
                            _page.Header.Controls.Add(appleicon57);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon60 = new HtmlLink();
                            appleicon60.Attributes["rel"] = "apple-touch-icon";
                            appleicon60.Href = "/images/logo/apple-icon-60x60.png";
                            _page.Header.Controls.Add(appleicon57);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon72 = new HtmlLink();
                            appleicon72.Attributes["rel"] = "apple-touch-icon";
                            appleicon72.Href = "/images/logo/apple-icon-72x72.png";
                            _page.Header.Controls.Add(appleicon72);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon76 = new HtmlLink();
                            appleicon76.Attributes["rel"] = "apple-touch-icon";
                            appleicon76.Href = "/images/logo/apple-icon-76x76.png";
                            _page.Header.Controls.Add(appleicon76);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon114 = new HtmlLink();
                            appleicon114.Attributes["rel"] = "apple-touch-icon";
                            appleicon114.Href = "/images/logo/apple-icon-114x114.png";
                            _page.Header.Controls.Add(appleicon114);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon120 = new HtmlLink();
                            appleicon120.Attributes["rel"] = "apple-touch-icon";
                            appleicon120.Href = "/images/logo/apple-icon-120x120.png";
                            _page.Header.Controls.Add(appleicon120);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon144 = new HtmlLink();
                            appleicon144.Attributes["rel"] = "apple-touch-icon";
                            appleicon144.Href = "/images/logo/apple-icon-144x144.png";
                            _page.Header.Controls.Add(appleicon144);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon152 = new HtmlLink();
                            appleicon152.Attributes["rel"] = "apple-touch-icon";
                            appleicon152.Href = "/images/logo/apple-icon-152x152.png";
                            _page.Header.Controls.Add(appleicon152);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink appleicon180 = new HtmlLink();
                            appleicon180.Attributes["rel"] = "apple-touch-icon";
                            appleicon180.Href = "/images/logo/apple-icon-180x180.png";
                            _page.Header.Controls.Add(appleicon180);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink androidicon = new HtmlLink();
                            androidicon.Attributes["rel"] = "icon";
                            androidicon.Href = "/images/logo/android-icon-192x192.png";
                            androidicon.Attributes["type"] = "image/png";
                            _page.Header.Controls.Add(androidicon);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink shortcut = new HtmlLink();
                            shortcut.Attributes["rel"] = "shortcut icon";
                            shortcut.Href = "/images/logo/favicon.png";
                            shortcut.Attributes["type"] = "image/png";
                            _page.Header.Controls.Add(shortcut);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            //JS
                            LiteralControl jquery = new LiteralControl();
                            jquery.Text = "";
                            _page.Header.Controls.Add(jquery);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            LiteralControl bootstrap = new LiteralControl();
                            bootstrap.Text = "";
                            _page.Header.Controls.Add(bootstrap);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            LiteralControl ayd = new LiteralControl();
                            ayd.Text = "";
                            _page.Header.Controls.Add(ayd);
                            _page.Header.Controls.Add(new LiteralControl("\n"));


                            LiteralControl analytics = new LiteralControl();
                            analytics.Text = "";
                            _page.Header.Controls.Add(analytics);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            //JS SONN

                            HtmlLink bootstrapcss = new HtmlLink();
                            bootstrapcss.Href = "/bootstrap/css/bootstrap.css";
                            bootstrapcss.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(bootstrapcss);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink awesome = new HtmlLink();
                            awesome.Href = "/bootstrap/font-awesome-4.7.0/css/font-awesome.min.css";
                            awesome.Attributes["rel"] = "stylesheet";
                            awesome.Attributes["type"] = "text/css";
                            _page.Header.Controls.Add(awesome);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink aydcss = new HtmlLink();
                            aydcss.Href = "/bootstrap/css/ayd.css";
                            aydcss.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(aydcss);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink search = new HtmlLink();
                            search.Href = "/bootstrap/css/search.css";
                            search.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(search);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink duyurular = new HtmlLink();
                            duyurular.Href = "/bootstrap/css/duyurular.css";
                            duyurular.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(duyurular);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink animate = new HtmlLink();
                            animate.Href = "/bootstrap/css/animate.min.css";
                            animate.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(animate);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink carousel = new HtmlLink();
                            carousel.Href = "/bootstrap/css/carousel-animation.css";
                            carousel.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(carousel);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink urunSlider = new HtmlLink();
                            urunSlider.Href = "/bootstrap/css/urunSlider.css";
                            urunSlider.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(urunSlider);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink box = new HtmlLink();
                            box.Href = "/bootstrap/css/box.css";
                            box.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(box);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink solBanner = new HtmlLink();
                            solBanner.Href = "/bootstrap/css/solBanner.css";
                            solBanner.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(solBanner);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink panel = new HtmlLink();
                            panel.Href = "/bootstrap/css/panel.css";
                            panel.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(panel);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink plans = new HtmlLink();
                            plans.Href = "/bootstrap/css/plans.css";
                            plans.Attributes["rel"] = "stylesheet";
                            _page.Header.Controls.Add(plans);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            HtmlLink googleapis = new HtmlLink();
                            googleapis.Href = "https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800italic,800&subset=latin,latin-ext";
                            googleapis.Attributes["rel"] = "stylesheet";
                            googleapis.Attributes["type"] = "text/css";
                            _page.Header.Controls.Add(googleapis);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            //YAPISAL VERİ İŞARETLEME ÖRNEĞİ 
                            LiteralControl yapisalveri = new LiteralControl();
                            yapisalveri.Text = "";
                            _page.Header.Controls.Add(yapisalveri);
                            _page.Header.Controls.Add(new LiteralControl("\n"));

                            #endregion
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        } 




 Etiketler:  htmlmeta metatag c# csharp htmllink