Di seguito é illustrato come inserire dinamicamente i meta tags ad una pagina web aspx.
protected void AddMetaTags(string Title, string Description, string Keywords, string Robots) { //Catturo l'header della pagina HtmlHead objHeader = (HtmlHead)Page.Header; //Aggiungo il meta tag Title Page.Title = Title; //Aggiungo il meta tag keywords HtmlMeta objMetaKeywords = new HtmlMeta(); objMetaKeywords.Name = "keywords"; objMetaKeywords.Content = Keywords; objMetaKeywords.Attributes.Add("id", "MetaKeywords"); //Aggiungo il tag all'header objHeader.Controls.Add(objMetaKeywords); //Aggiungo il meta tag description HtmlMeta objMetaDescription = new HtmlMeta(); objMetaDescription.Name = "description"; objMetaDescription.Content = Description; objMetaDescription.Attributes.Add("id", "MetaDescription"); //Aggiungo il tag all'header objHeader.Controls.Add(objMetaDescription); //Aggiungo il meta tag robots HtmlMeta objMetarobots = new HtmlMeta(); objMetarobots.Name = "robots"; objMetarobots.Content = Robots; objMetarobots.Attributes.Add("id", "MetaRobots"); //Aggiungo il tag all'header objHeader.Controls.Add(objMetarobots); }
Aggiungere dinamicamente i MetaTags ad una pagina aspx
Pubblicato il Sviluppo sw