''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Canonical URL fix in DotNetNuke for search engine optimization
'Author: Codex-m
'Website: www.dotnetdevelopment.net/www.php-developer.org
'License: Open source
'FOR DETAILED DOCUMENTATION: Find this tutorial in www.aspfree.com: Canonicalizing DotNetNuke URLs in ASP.NET 3.5
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''
'START OF CANONICAL SCRIPT''
''''''''''''''''''''''''''''
'Declare urlofpage as a string
Dim urlofpage As String
Dim canonicalurl As String
Dim blogposturlcheck As Integer
Dim requesturl As String
Dim linkrelcanonicalcode As String
Dim blogcategoryurlcheck As String
'Get the Requested URL not the Global DotNetNuke URL
requesturl = Request.Url.ToString()
'Get the Global DotNetNuke URL of the page
urlofpage = DotNetNuke.Common.Globals.NavigateURL()
'convert all URLs to lower case to simplify processing and prevent further canonical issues in Google.
urlofpage = LCase$(urlofpage)
'Solve canonical issue processing between home.aspx, default.aspx and / in DotNetNuke
If urlofpage = "http://localhost/dotnetnukewebsite/home.aspx" Then
canonicalurl = "http://localhost/dotnetnukewebsite/"
linkrelcanonicalcode = ""
'Output canonical URL
linkrelcanonical.Text = linkrelcanonicalcode
End If
'Check if the URL is a DotNetNuke Blog Post URL
blogposturlcheck = InStr(1, requesturl, "EntryId", vbTextCompare)
'Check if the URL is a DotNetNuke Blog Category URL
blogcategoryurlcheck = InStr(1, requesturl, "catid", vbTextCompare)
'Solve lower and upper case issues between other URLs except home.aspx, default.aspx, / , Blog Post URL
If urlofpage <> "http://localhost/dotnetnukewebsite/home.aspx" And blogposturlcheck = 0 And blogcategoryurlcheck = 0 Then
canonicalurl = urlofpage
linkrelcanonicalcode = ""
'Output canonical URL
linkrelcanonical.Text = linkrelcanonicalcode
End If
'Solve canonical URL issues in DotNetNuke Blog Modules (Blog posts URL only, category URLs are not included because
'they cannot be called as canonical URLs and can be simply be tag with programmatically
'as a simpler solution
'Count the entire URL length, do URL string manipulation in order to get extract the post and category ID
Dim value As Integer
value = requesturl.Length
If blogposturlcheck <> 0 Then
'URL string manipulation for post id
Dim startpositionblogurl As Integer
startpositionblogurl = 7 + blogposturlcheck
Dim endpositionblogurl As Integer
endpositionblogurl = value - startpositionblogurl
Dim blogid As String
blogid = requesturl.Substring(startpositionblogurl, endpositionblogurl)
'Retrieve DotNetNuke permalink URL from database
Dim myCommand As SqlCommand = New SqlCommand()
myCommand.Connection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
myCommand.Connection.Open()
myCommand.Parameters.AddWithValue("@blogid", blogid)
myCommand.CommandText = "SELECT PermaLink FROM Blog_Entries WHERE EntryID=@blogid"
Dim retrievevalue As SqlDataReader = myCommand.ExecuteReader()
While retrievevalue.Read()
Dim permalinkpost As String
permalinkpost = CStr(retrievevalue("PermaLink"))
'Convert post URL entirely to lower case
permalinkpost = LCase$(permalinkpost)
canonicalurl = permalinkpost
'Output canonical URL
linkrelcanonicalcode = ""
'Output canonical URL
linkrelcanonical.Text = linkrelcanonicalcode
End While
retrievevalue.Close()
myCommand.Connection.Close()
End If
''''''''''''''''''''''''''
'END OF CANONICAL SCRIPT''
''''''''''''''''''''''''''