Add Canonical Link to your Header using ASP.Net Code behind
Google and other search engines have added a new tag called canonical to the list of header items they will scan on your website. The idea is to start a cleanup of duplicate items on the internet.
As i use and maintain a whole bunch of websites i needed to get this new tag added automatically with .net
The following code can be added to the Page load event in your master page or a normal aspx page.
Dim canonicalLink As New HtmlLink()
canonicalLink.Href = HttpContext.Current.Request.Url.ToString
canonicalLink.Attributes.Add("rel", "canonical")
Page.Header.Controls.Add(canonicalLink)
This will added the new canonical tag to your header section automatically for all search engines.
Example
<link rel=”canonical” href=”product.php?item=swedish-fish” />
You can read more on the Google Blog
AJAX AutoCompleteExtender using Google Suggest API in VB.net
I have been looking for a good online example on the AutoCompleteExtender and all i could find was loads and loads of c# examples. But my website is in vb.net so i converted some c# into vb.net for you. So below you will see how to create a webservice that calls the Google Suggest API in vb.net and then how to use it with a ASP.net ajax autocompleteextender.
First the WebService Code;
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Collections
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:=”http://tempuri.org/”)> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AutoCompleteSearch
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetGoogleSearchResults(ByVal prefixText As String, ByVal count As Integer) As String()
Dim doc As New XmlDataDocument
Dim suggArList As New List(Of String)
Dim url As String = “http://google.com/complete/search?output=toolbar&q=” & prefixText
Dim node As XmlNode
doc.Load(url)
Dim value As String
For Each node In doc.SelectNodes(”//CompleteSuggestion”)
value = node.SelectSingleNode(”suggestion/@data”).InnerText
suggArList.Add(value)
Next
Return suggArList.ToArray
End Function
End Class
Then you will need to add the text box and autocompleteExtender to your webpage or Web User Controls.
<%@ Register Assembly=”AjaxControlToolkit” Namespace=”AjaxControlToolkit” TagPrefix=”cc1″ %>
<asp:ScriptManagerProxy ID=”ScriptManagerProxy1″ runat=”server”>
<Services>
<asp:ServiceReference Path=”~/WebServices/AutoCompleteSearch.asmx” />
</Services>
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
<ContentTemplate>
<asp:TextBox ID=”q” CssClass=”g-prettysearch” runat=”server”></asp:TextBox>
<cc1:AutoCompleteExtender ID=”q_AutoCompleteExtender” runat=”server” DelimiterCharacters=”"
Enabled=”True” ServicePath=”~/WebServices/AutoCompleteSearch.asmx” ServiceMethod=”GetGoogleSearchResults”
TargetControlID=”q” MinimumPrefixLength=”1″ CompletionSetCount=”4″ CompletionInterval=”10″>
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
Once you have done this then you are ready to go. I have not posted the files for download but if you need the example emailed please let me know gerhard@purpleolive.net