locked
meta tags for multilingual site RRS feed

  • Question

  • User472828542 posted

    How to specify meta tags, when the site is dynamic...i.e the data on the page is read from database/resource file.....there is a single .aspx page for all languages?

    How to generate the keywords for meta tags dynamically?

    Friday, March 23, 2007 7:20 AM

Answers

  • User-2080354364 posted

    I would suggest you to create a PageBase class and derive all your pages from it.

    You can override the OnLoad method and add logic to retrieve the keywords, description or any other meta tags and add them to your header.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    // you will need the HtmlControls namespace for the HtmlMeta classusing System.Web.UI.HtmlControls;
    using IntraCube.Web.Core;
    
    public partial class _default : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    			// add your logic to retrieve meta data depending on the current culture
    			// the code assumes that the getKeywordsByCulture and getDescriptionByCulture methods retrieve the appropriate strings by the RawUrl and Culture
    			HtmlMeta meta = new HtmlMeta();
    			meta.Name = "keywords";
    			meta.Content = getKeywordsByCulture(this.UICulture, Request.RawUrl);
    			Page.Header.Controls.Add(meta);
    			meta = new HtmlMeta();
    			meta.Name = "description";
    			meta.Content = getDescriptionByCulture(this.UICulture, Request.RawUrl);
    			Page.Header.Controls.Add(meta);
        }
    
    }
     Hope it helps and please let me know if it works for you
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 23, 2007 12:32 PM

All replies

  • User-2080354364 posted

    I would suggest you to create a PageBase class and derive all your pages from it.

    You can override the OnLoad method and add logic to retrieve the keywords, description or any other meta tags and add them to your header.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    // you will need the HtmlControls namespace for the HtmlMeta classusing System.Web.UI.HtmlControls;
    using IntraCube.Web.Core;
    
    public partial class _default : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    			// add your logic to retrieve meta data depending on the current culture
    			// the code assumes that the getKeywordsByCulture and getDescriptionByCulture methods retrieve the appropriate strings by the RawUrl and Culture
    			HtmlMeta meta = new HtmlMeta();
    			meta.Name = "keywords";
    			meta.Content = getKeywordsByCulture(this.UICulture, Request.RawUrl);
    			Page.Header.Controls.Add(meta);
    			meta = new HtmlMeta();
    			meta.Name = "description";
    			meta.Content = getDescriptionByCulture(this.UICulture, Request.RawUrl);
    			Page.Header.Controls.Add(meta);
        }
    
    }
     Hope it helps and please let me know if it works for you
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 23, 2007 12:32 PM
  • User-2080354364 posted

    For some reason the

    using System.Web.UI.HtmlControls;

    doesn't show up correctly and sorry you don't need to override the OnLoad method. You can just add the Page_Load function just as above. If you are not using master page and you want to use local resources instead of retrieving data from the database, you can consider using the following code instead:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="" Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Your Page Title</title>
        <meta id="metaKeywords" name="keywords" content="" runat="server" meta:resourcekey="PageKeywords" />
        <meta id="metaDescription" name="description" content="" runat="server" meta:resourcekey="PageDescriptions" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
    

     

    Generate your Local Resources and add PageKeywords.Content and PageDescription.Content as the resource string name. Set the Values appropriately and add any other cultures you may need.

    Friday, March 23, 2007 12:47 PM
  • User-2080354364 posted

    For some reason the

    using System.Web.UI.HtmlControls;

    doesn't show up correctly and sorry you don't need to override the OnLoad method. You can just add the Page_Load function just as above. If you are not using master page and you want to use local resources instead of retrieving data from the database, you can consider using the following code instead:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="" Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Your Page Title</title>
        <meta id="metaKeywords" name="keywords" content="" runat="server" meta:resourcekey="PageKeywords" />
        <meta id="metaDescription" name="description" content="" runat="server" meta:resourcekey="PageDescription" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
    

     

    Generate your Local Resources and add PageKeywords.Content and PageDescription.Content as the resource string name. Set the Values appropriately and add any other cultures you may need.

    Friday, March 23, 2007 12:47 PM
  • User764555827 posted

    Hi Annu,

    Visual Studio 2005 will generate the meta tags for you. Just follow my tutorial for translating ASP.Net Web sites.

    Hope this helps,

    Arnaud 

    Friday, March 23, 2007 4:56 PM