Welcome to MSDN Blogs Sign in | Join | Help

jhawk's WebLog

Jonathan Hawkins, Software Architect for ASP.NET, AJAX, Silverlight, .NET Framework
Search enabling Silverlight and AJAX web applications

The major search engines index HTML text elements (body text, title, image alt text, etc) and following anchor tag (<a href= />) links. Currently none of the search engines index XAML.

 

However many Silverlight web applications have dynamic experiences that are driven by code running in the browser. In Silverlight 1.0 this is Javascript and in Silverlight 1.1 this will include manage code languages such as C#, VB, etc. The code may be as simple as generating dynamic UI fragments on the fly all the way from a static list of data to dynamically obtaining data from a database/web service and generate UI fragments and adding them to the UI experience. Thus even when search engines get around to indexing static .xaml content which is good first step it will still be a partial solution as most of the content will be dynamic.

 

I gave a talk (with Nathan Buggia from Live Search) at MIX07 about search enabling dynamic content including Silverlight content. You can download the deck, view the video from my blog posting. The Silverlight content is about half way into the video. Download the end to end Northwind sample here that has the ProductSL.aspx which is Silverlight enabled . The sample also has a product data search provider against SQL Server, dynamic data sitemaps, navigation data links control. Below are the relevant highlights from the talk:

 

Sitemaps

The major search engines supports sitemaps which are great way to give hints to the search engine as to which pages (URLs) are important in the site, the priority of the page relative to the other page in the site, change frequency (daily, weekly, etc) and when the page was last modified. This is a good way to point search engines at the right set of pages in the web site. The ASP.NET Futures CTP has features to enable you to have multiple code driven dynamic sitemaps. This can be used for ASP.NET, AJAX and Silverlight web applications. There is a quickstart tutorial.

 

 “ALT text for dynamic content”

Search engines can’t index static XAML (not yet) and they can’t index dynamically generated XAML.  If we look at how image tags are handled by search engines, the search engines may index the image name in the src attribute however they don’t index the actual JPEG/GIF image, they do however also index the alt=”sometext” attribute. The point being they index the textual attributes for the image tag.

 

So for dynamic pages you could have dynamic Silverlight/AJAX content in a <div id=”dynamic_content” > and static text and navigation links hints (below) in <div id=”flat_content” >. The flat_content div can be thought of as the “ALT text” for the dynamic content. For data/service driven web applications you can add a small number of HTML text hints. You can do this very easily using .aspx controls and a small amount of LINQ/ADO.NET code. For static information you could even place the data directly inline as HTML in the flat_content div and data bind to that by parsing the HTML . Update: Nikhil has a great post wrt inlining data in HTML to help with SEO.

 

You need to ensure that the web application returns the same page to a search engine that would be returned to a regular browser. The search engines frown upon returning different pages to them and may even ban (blacklist) the web site if different content is returned. Below is a optimization (just one option) to remove the unneeded flat HTML in the flat_content div if the browser has javascript enabled … and thus staying true to the tenet of returning the same content to browsers and search engines.

 

<script type="text/javascript">

    document.getElementById("flat_content").setAttribute("innerHTML","");

</script>

 

Navigation Hyperlinks and Query Strings

Many Silverlight/AJAX web applications have one (or a small number pages) page that directly update the UI experience in the browser without page-to-page navigation thus there are no navigation anchor tags (URLs) for the search engines to follow. You can give the search engines help by providing anchor tags that point back to the page with navigation information in the query string. When the page loads just parse the query string in the page load and display the request UI. In Silverlight 1.1 you can access the query string using the managed code HtmlPage.QueryString api. These navigation anchor tag and query string hints will help the search engine follow all the links in the site and so obtain the relevant text keywords for its index. When the user searches in the search engine for a keyword, the Silverlight/AJAX will have a keyword match and included in the search results. When the user clicks on the search result they will be presented with the full Silverlight enabled experience.

 

Enjoy

Jonathan

Search Capabilities for Dynamic ASP.NET Web Content

Last week at MIX07 Nathan Buggia and I presented a talk on Search enabling dynamic web content applications including ASP.NET and Silverlight web applications. Download the deck and stream or download the video.

Updated 

The BasicSearch.zip sample demonstrates how to use the SearchDataSource, search providers and turn your ASP.NET navigation into a search site map that can be consumed by the major search engine. Download the ASP.NET Futures CTP and copy the Microsoft.Web.Preview.dll into the bin directory.

You can find QuickStarts on Search and Search Site Maps to learn more. It will also show how to write your own search provider. I have included sample code search providers for Index Server and Yahoo! search.

enjoy
Jonathan

 

 

 

Cool Mashup: Location Based Events

Neil wrote a cool location events mashup based my earlier Atlas Map sample.
Cool work!

SQL Server Everywhere CTP

Steve Lasker has some great material on his blog about the recent SQL Server Everywhere CTP announcement. The download is just 1.7MB, which is smaller than a hi-resolution picture from my Canon digital camera. The same database that runs on my Audiovox SmartPhone now enabled for the XP, WS03, Vista machines. Very light and easy to install.

enjoy
-jhawk

Windows Keyboard Shortcuts

A couple of of my favorite keyboard shortcuts:

Task Manager - Ctrl+Shift+Esc            Do a check on memory and CPU usage
Run a program - Window Key + R       Start cmd
Start Explorer - Windows Key + E       Manage filesystem

You can find a nice list at: Keyboard shortcuts for Windows

enjoy
-jhawk

Building a Mashup of National Parks using the Atlas Virtual Earth Map control

Atlas has a great map control for Virtual Earth (also known as Windows Live Local). The map control makes it super easy to build a mashup with Atlas of displaying the locations of a couple of National Parks on a map.

 

The posting describes how to add and display pushpins on the map. You can download the full source-code to the application here. Updated: You can run the app on the web here. You can re-use or modify the code.

 

After the screenshots below, we will go through the steps to build the basic map parts of the application.

 

A good way to learn about it yourself is to download the sample and run it on your local system (note: if you have the free Visual Web Developer Express tool (or VS 2005) installed then you should be able to just copy the above .zip file to your local hard-drive, expand it, open the web-site and hit run).  Note: I used CSS for the style information.

 

I have also included an expanded page (default.aspx) which includes searching, listview for results and displaying pushpins on the map.

 

Quick Tour of the Application

 

The basic steps map0 (basic map), map1 (pushpin), map2 (multiple pushpins from a web service), map3 (navigation). go through the steps of adding a map, displaying pushpins and basic navigation (note: the screenshots are done with FireFox – it also works with IE as well): 

 

 

The expanded page (default.aspx) provides a simple query of National Parks by state and displays them in a listview on the left and a virtual earth map on the right. You can click on the images to link NPS web pages with additional information. You can also hover on the map pushpins to display the push pun popup. (note: the screenshots are done with FireFox – it also works with IE as well): 

 

 

We can type a state in the Search textbox such as California. Notice the autocomplete. If we choose California and click the Search button the listview will be populated, see the next screenshot below.

 

  

Here we see the image, title and description on the left in the listview and pushpin displayed on the map on the left. If we hover over the pushpin a popup will appear, see the next screenshot below.

 

 

Here we see the map pushpin popup. We can click on the popup image to navigate to the NPS website.

 

 

Steps to building something like this

 

If you want to build as basic version of this you’ll want to follow the steps below:

 

Step 1) Create a new web-site using the free Visual Web Developer Express Tool (or VS 2005) and the March 2006 CTP Atlas Project Template

 

 

Step 2) Add a new css stylesheet default.css to the project Website -> Add New Item -> stylesheet

 

 

 

Step 3) Add the following items to the default.css stylesheet. We will add additional items to the stylesheet in the steps below.

 

    body

    {

        font-family: Verdana, Helvetica, sans-serif;

        color: #000000;

        background: #0B0B0A

        margin: 0px;

    }

 

    #map1

    {

        position: absolute;

        width: 800px;

        height: 600px;

    }

 

Step 4) In default.aspx web page <head> add a stylesheet reference to the default.aspx

 

  <link type="text/css" rel="stylesheet" href="default.css" />

 

Step 5) In default.aspx add the Virtual Earth Map stylesheet. Be sure to include the ref=”stylesheet” attribute.

 

  <link type="text/css" rel="stylesheet" href="http://dev.virtualearth.net/standard/v2/MapControl.css" />

 

Step 6) Add an atlas:ScriptManager and a ScriptReference for the AtlasUIMap.

 

    <atlas:ScriptManager runat="server" ID="scriptManager">

      <Scripts>

        <atlas:ScriptReference ScriptName="AtlasUIMap" />

      </Scripts>

    </atlas:ScriptManager>

 

Step 7) Add a div for the map to render into

 

    <div id="map1" style="width: 800px; height: 600px; overflow: hidden">

    </div>

 

Step 8) Add the virtualEarthMap control to the xml-script section

 

  <script type="text/xml-script">

    <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

      <components>

        <virtualEarthMap id="map1" latitude="42.641025" longitude="-96.240234" zoomLevel="4" mapStyle="Hybrid">

        </virtualEarthMap>

      </components>

    </page>

  </script>

 

Step 9) Your .aspx page markup should look like this:

 

<%@ Page Language="C#" %>

 

<!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>

  <title>Map 0 - Atlas Virtual Earth Map Control on webpage</title>

  <link type="text/css" rel="stylesheet" href="default.css" />

  <link type="text/css" rel="stylesheet" href="http://dev.virtualearth.net/standard/v2/MapControl.css" />

</head>

<body>

  <form id="form1" runat="server">

    <atlas:ScriptManager runat="server" ID="scriptManager">

      <Scripts>

        <atlas:ScriptReference ScriptName="AtlasUIMap" />

      </Scripts>

    </atlas:ScriptManager>

    <div id="map1" style="width: 800px; height: 600px; overflow: hidden">

    </div>

  </form>

 

  <script type="text/xml-script">

    <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

      <components>

          <virtualEarthMap id="map1" latitude="42.641025" longitude="-96.240234" zoomLevel="4" mapStyle="Hybrid">

          </virtualEarthMap>

      </components>

    </page>

  </script>

 

</body>

</html>

 

Step 10) Viewing it in the browser should look like this (Map0.aspx):

 

 

 

Step 11) Next we will add a single pushpin to the map. First add the following to default.css

 

    .item

    {

        position:relative;

        background-color: lightyellow;

        border: 1px solid #aaa;

        padding: 2px 2px 2px 10px;

        width: 275px;

    }

 

    .itemContainer

    {

        width: 250px;

        position:relative;

        z-index: 501;

    }

 

    .logo

    {

        width: 100px;

        height: 64px;

        float: left;

        margin: 5px 5px 0px 0px;

    }

 

Step 12) In the xml-script section of the .aspx add an application element with a load attribute that points to the javascript function that will execute when the page first starts.

 

  <script type="text/xml-script">

      <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

        <components>

 

            . . .   

          <application load="onLoad">

          </application>         

         

            . . .

 

        </components>

      </page>

  </script>

 

Step 13) Add the following javascript code to the .aspx page. The code defines an array for pushpins. In this instance we add just one. You can add additional pushpins. There are fields for Id, Latitude, Longitude, Name, ImageUrl, MoreInfoUrl and Description. The set_data method on the virtual earth map databinds to the pushpins.

 

    <script type="text/javascript">

      function onLoad() {

          var pushpins = [

            {Id:0,Latitude:46.851734,Longitude:-121.759874,Name:"Mount Rainier National Park",ImageUrl:"http://www.nps.gov/applications/parkphotos/MORAFromLongmireJune2002-4.jpg",MoreInfoUrl:"http://nps.gov/mora", Description:"<p>Established in 1899. 235,625 acres (97% is designated Wilderness). Includes Mount Rainier (14,410&#39;), an active volcano encased in over 35 square miles of snow and ice. The park contains outstanding examples of old growth forests and subalpine meadows.</p>" }

          ];

          document.getElementById("map1").control.set_data(pushpins);

      }

    </script>

 

Step 14) Add a template for the popup for the map pushpin to the .aspx page

 

    <div style="display: none;">

      <div id="map1_popupTemplate">

        <div class="item">

          <a href="" id="map1_popupTemplate_imagemoreinfolink" target="_blank">

            <img id="map1_popupTemplate_logo" alt="" src="" />

          </a>

          <span id="map1_popupTemplate_name"></span>

          <br />

          <span id="map1_popupTemplate_description"></span>

        </div>

      </div>

    </div>

 

Step 15) Update the virtualEarthMap control in the xml-script to include the popupTemplate element definition and additional attributes on the virtualEarthMap to enable data binding.

 

  <script type="text/xml-script">

      <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

        <components>

          <virtualEarthMap id="map1" latitude="42.641025" longitude="-96.240234" zoomLevel="4" mapStyle="Hybrid" popupPositioningMode="BottomLeft" pushpinActivation="Hover" pushpinImageURL="Images/pushpin.png" pushpinImageWidth="0" pushpinImageHeight="0" popupCssClass="itemContainer" dataLatitudeField="Latitude" dataLongitudeField="Longitude" dataImageURLFormatString="{0}" dataTextFormatString="{0}" dataValueField="Id">

            <popupTemplate>

              <template layoutElement="map1_popupTemplate">

                <hyperLink id="map1_popupTemplate_imagemoreinfolink">

                  <bindings>

                    <binding dataPath="MoreInfoUrl" property="navigateURL" />

                  </bindings>

                </hyperLink>

                <image cssClass="logo" id="map1_popupTemplate_logo">

                  <bindings>

                    <binding dataPath="Name" property="alternateText" />

                    <binding dataPath="ImageUrl" property="imageURL" />

                  </bindings>

                </image>

                <label cssClass="itemNameLabel" id="map1_popupTemplate_name">

                  <bindings>

                    <binding dataPath="Name" property="text" />

                  </bindings>

                </label>

                <label id="map1_popupTemplate_description">

                  <bindings>

                    <binding dataPath="Description" property="text" />

                  </bindings>

                </label>

              </template>

            </popupTemplate>

          </virtualEarthMap>

   

          <application load="onLoad">

          </application>         

         

        </components>

      </page>

  </script>

 

Step 16) View the .aspx page in the browser and it should look like the following (Map1.aspx):

 

 

Step 15) Hover over the pushpin and the popup with show. Click on the image in the popup to navigate to NPS page.

 

 

 

Step 17) Add a new C# class to the App_Code directory called MapItemRow.cs with the following code which describes a class with properties for our pushpin.

 

using System;

using System.ComponentModel;

 

public class MapItemRow

{

    private int _id;

    private string _category;

    private string _name;

    private string _imageUrl;

    private string _description;

    private double _latitude;

    private double _longitude;

    private string _moreInfoUrl;

 

    [DataObjectField(true)]

    public int Id

    {

        get { return _id; }

        set { _id = value; }

    }

 

    [DataObjectField(false), DefaultValue("")]

    public string Name

    {

        get { return _name; }

        set { _name = value; }

    }

 

    [DataObjectField(false), DefaultValue(0)]

    public double Latitude

    {

        get { return _latitude; }

        set { _latitude = value; }

    }

 

    [DataObjectField(false), DefaultValue(0)]

    public double Longitude

    {

        get { return _longitude; }

        set { _longitude = value; }

    }

 

    [DataObjectField(false), DefaultValue("")]