Last post Jun 01, 2015 05:26 AM by Li Wang
May 30, 2015 06:34 AM|Claudio7810|LINK
I am trying to optimize the backend for my database driven website and I am kind of stuck on how to manage metatags.
I have read many sources and approaches about this topic and still I don't feel I reached the best solution and some brainstorming with you guys would for sure help me understand better what is going to be the best approach to follow.
I ll give you some insights about how I am managing my website: all the content of my website is managed dynamically from my backend: text, pictures, maps etc. are all added to database and they automatically populate my website. This means that when I
add, let's say a new continent, let's say Africa, a new dynamic page is added to the website in the form of: http://www.mysite.com/continents/africa
In order to populate this new page with meta tags I am using the following code in masterpage:
Partial Class admin_MasterPage
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim page As String = Request.Url.Segments(Request.Url.Segments.Length - 2)
Dim dtMeta As DataTable = Me.GetData(page)
'Add Page Title
Me.Page.Title = dtMeta.Rows(0)("Title").ToString()
'Add Keywords Meta Tag
Dim keywords As New HtmlMeta()
keywords.HttpEquiv = "keywords"
keywords.Name = "keywords"
keywords.Content = dtMeta.Rows(0)("Keywords").ToString()
'Add Description Meta Tag
Dim description As New HtmlMeta()
description.HttpEquiv = "description"
description.Name = "description"
description.Content = dtMeta.Rows(0)("Description").ToString()
Private Function GetData(page As String) As DataTable
Dim query As String = "SELECT Title, Description, Keywords FROM MetaTags WHERE LOWER(Page) = LOWER(@Page)"
Dim constr As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(query)
Using sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
sda.SelectCommand = cmd
Dim dt As New DataTable()
The meta tags are added correctly to every single page when I add into my database the last URL segment (africa in this case) that has been created and populate the table with the description, key words and title.
What I don't like in this approach:
What would you suggest to implement/modify in order to solve the 2 above points?
Thank you so much in advance
Jun 01, 2015 05:26 AM|Li Wang|LINK
Thank you for your post.
According to your description, I suggest you record all the segments of url in your page column.
Code blow is for your reference.
Dim page As String = Request.Url.AbsolutePath
Hoping my reply could be helpful to you.