If you're using the ASP.net site and you want it to search Engine friendly, chances are you want it to have a sitemaps. Here we are not talking about ASP.net's sitemap, but Sitemaps.org's xml-based sitemaps protocol, note the case of the two names, and the single plural, which I then distinguish. The Sitemaps protocol is a bit like RSS or Atom, but it describes not the recent content update, but the entire site map, mainly to describe the importance of specific URLs, update time and frequency. Search engines such as Google support Sitemaps, through Google Webmaster Tools (formerly known as Google Sitemaps) you can submit your site sitemaps, so that Google better index your site.
Simple call
Before ASP.net futures (May CTP), if you want to add sitemaps support for your asp.net site, I'm afraid I have to implement a special page (or HttpHandler) for reading asp.net Sitemap and output as Sitemaps protocol. And now this job can be handed over to ASP.net futures Aspnetsitemapsearchsitemapprovider, all you have to do is write a few sentences in web.config. Because this feature belongs to the Searchsitemap category in ASP.net futures, the section needs to be configured in Web.config:
The following are the referenced contents:
<microsoft.web.preview> <searchsitemap enabled= "true" > <providers> <add name= "navigation" type= "Microsoft.Web.Preview.Search.AspNetSiteMapSearchSiteMapProvider, Microsoft.Web.Preview "/> </providers> </searchSiteMap> </microsoft.web.preview> |
In this configuration, we enable SEARCHSITEMAP, and then configure a provider named "Navigation", this provider uses the Aspnetsitemapsearchsitemapprovider class, it is so simple , and configured in exactly the same form as any other provider. Then you also need to make sure that the relevant HttpHandler configuration well, if you create a new site using the template is ASP.net futures, then HttpHandler should be configured, configuration information as follows:
The following are the referenced contents:
<add verb= "*" path= "Searchsitemaps.axd" type= "Microsoft.Web.Preview.Search.SearchSiteMapHandler" True "/> |
At this point, if your site has been properly enabled asp.net own sitemap features, such as the use of static Web.sitemap, then access to Searchsitemap.axd should be able to see the results of the SITEMAPS protocol output. This time you may be surprised, why only one record of the results? This is the recursive invocation of Sitemaps, the master sitemaps only the address of the Sitemaps we had previously configured named "Navigation", which is searchsitemaps.axd?sitemap=navigation. Open this address and you will find that it is still a sitemaps that contains the data provided by the ASP.net sitemap.
Take a closer look
Next, we use reflector to see how some of the classes below Microsoft.Web.Preview.Search are implemented. I am not prepared to analyze the code in detail, because the code is very simple, just talk about the results of the finished bar. If you've seen something missing from the Sitemap-generated sitemaps, you'll know how to add to the project. The Sitemaps protocol contains information about a URL that can include the following:
Address: The URL itself
Last Update time
Update frequency: How often is the content of this URL updated
Importance: A value of 0 to 1, the default value of 0.5, the search engine does not necessarily based on this value to determine the true importance of the URL
However, the auto-generated Sitemaps only includes the first two messages, and if we need the latter two messages, we need to increase them manually. How to manually increase it? Because SiteMapNode is similar to a dictionary and has access to this [string key], so long as sitemapnode[] exists "lastmodified"/"changefrequency"/"Priority" These values are automatically exported to Sitemaps, and "LastModified" overwrites the actual last update time of the page's ASPX file.
A simple example of how this function is used, assuming you are using static Web.sitemap, we have been accustomed to this definition of a SiteMapNode:
The following are the referenced contents:
<sitemapnode url= "default.aspx" title= "Welcome" description= ""/> |
Adding a specific attribute requires only this definition:
The following are the referenced contents:
<sitemapnode url= "default.aspx" title= "Welcome" "description=" "Daily" changefrequency= "priority=" 0.8 |
Support Dynamic Data
With so much to say, it is only possible to support the system from the Sitemap, and in fact Searchsitemap can also provide special support for dynamic Data. Dynamic data is simple and easy to use, as if Ruby on Rails supports scaffolding and previews the future of ASP.net in agile. For more information about dynamic Data control, refer to Dflying's article, where we discuss only the support of Searchsitemap:
Preliminary study on ASP.net futures--Dynamic Data control: Getting Started
A preliminary study of ASP.net futures-Dynamic Data control: deep
To support Dynamic Data, you first need to implement your own dynamicdatasearchsitemapprovider. We do not see to inherit from the system class to implement their own class is very complex things, in fact, we only need to override off a function, that is, Dynamicdatasearchsitemapprovider.dataquery (). In this function, we need to return a IEnumerable, where the elements need to have the primary key column name attribute and the following properties:
The following are the referenced contents: Sitemaplastmodified Sitemapchangefrequency Sitemappriority |
You may well ask, why not determine the type of IEnumerable rather than the type of list<>? Think about what part of the. NET Framework uses IEnumerable most, that is, LINQ. If you are using LINQ to filter data directly in Querydata (), you do not need to create custom types and populate IEnumerable yourself. Moreover, the primary key column name is not determined, and if you record its name with one attribute and record its value with another attribute, that's a hassle, so ASP.net futures chose the aforementioned LINQ advantage.
Finally, I personally feel that there is something wrong with Searchsitemapproviderbase's design, It serves as the base class for Aspnetsitemapsearchsitemapprovider and Dynamicdatasearchsitemapprovider, including the Querydata () method, However, this method is used only by Dynamicdatasearchsitemapprovider, and it is obvious that it should be placed inside the dynamicdatasearchsitemapprovider.