Blogg om Umbraco och CMS

IIS Search Engine Optimization (SEO) Toolkit

This wednesday, the legendary ScottGu visited Stockholm for the first time ever. He had an event at the China Theater. There were 1200 developers interested to hear what Scott had to say about Microsoft's upcoming products, Visual Studio 2010, MVC2 and Silverlight 4.

ScottGu at China Theatre in Stockholm

I could probably write two or three blog entries on everything he said, but I will not do that. What stuck in my mind, and wasted half my work day after that, was a small tip on IIS Search Engine Optimization (SEO) Toolkit that Microsoft has released.

IIS Search Engine Optimization (SEO) Toolkit

You can easily intall IIS Search Engine Optimization (SEO) Toolkit with the Web Platform Installer -> Web Platform -> Web Server -> Search Engine Optimization (SEO) Toolkit. When it's installed, just open up the IIS manger and start testing your sites (or others if you think it's fun to examine people who consider themselves to be SEO experts). I ran a test on . The result: 111 links, ~400 errors / warnings. The great thing is that all errors / warnings are very detailed in the toolkit and (in my case) most of them are very easy to fix. IIS Search Engine Optimization (SEO) Toolkit warns of everything from Canonical URL's to the lack of alt tags for images.

Reports

When you run an analysis of a page, whichever page, running on whichever Web Server (Apache, IIS, etc.), you get a somewhat not flattering summary. In my case I had 111 links and over 400 errors. Clicking on the Violations, leads to a clearer picture of what is wrong, and how many of the same errors you have. One of my big problems (which I knew already) was that I duplicate the entire contents of both sewen.se and www.sewen.se. I have known that this is a problem, but havn't really cared about it until now when I got it thrown in my face. 

IIS SEO Toolkit analysis report

By clicking on a violation you get even more information about the source of the problem.The Violation-tab provides a descriptive text of what the fault is, and a recommended solution. Undert the other tabs, you can read everything from source on the page that the error occurred on to all the in- / out links the specific page has (good for finding canonical URL's). 

IIS SEO Toolkit

Final thoughts

This was by no means an exhaustive blog entry on the IIS, Search Engine Optimization (SEO) Toolkit.This was more meant to be a tip. Anyway after 1-2 hours of work to check off the report list, I am down on 38 errors / warnings, most of which is that I do not have description META-tags. As I understand (correct me if I'm wrong), the description tags doesn't give you better search engine results, but accounts for the presentation of the pages. Therefore I feel that I in good conscience can concentrate on other things.

But it will probably be another analysis within short to see what new nonsense you find yourself doing wrong.

Read more

http://www.iis.net/expand/SEOToolkit
http://weblogs.asp.net/scottgu/archive/2009/06/03/iis-search-engine-optimization-toolkit.aspx

Friday, December 04, 2009

Recursive function in .NET to get descendant nodes

A while ago, there turned up a question on our.umbraco.org on how to get hold of all the descendant nodes of a specific document with a .NET function. View the entire thread here.

The question was answered, but I'm not really keen on working with XPath in .NET so I thought I'd propose a recursive approach instead.

The idea of a recursive function is that you walk up the branches in the tree, until you reach a leaf. Then return, to see if there are more branches / leaves on the branch. For example;

We have the structure

-2009
-- 8
--- 19
-- 10
--- 16
--- 22
-- 11
--- 6

In this case, our recursive function start of 2009. When we ask for Children for 2009 it returns 8,10,11.

We then walk up the 8 and ask for Children. 8 will return 19. We see then that 19 is a leaf, and therefore adds it to our list.

Then we return and come back to the 8. Since 8 does not have any more Children, we also add 8 to our list, and return.

We're back to 2009 and proceed along the next branch which is 10. 10 has two leaves 16 and 22. We add these two and return to 10, and adds that also.

On the way it is. Or that Sluggo would explain it:

sluggo_dreaming

To the programming

We start by adding properties that we know we will need. One for the start node and one for the document type.

TIP! You know that you can write prop + tab + tab to get an automatic generation of properties in Visual Studio.

        private int rootNode = 0;
        public int RootNode { get { return rootNode; } set { rootNode = value; } }
        
        private string documentTypeAlias = "";
        public string DocumentTypeAlias { get { return documentTypeAlias; } set { documentTypeAlias = value; } }

Then we go into the Page_Load and declare our list and begin our recursive function, to which we are submitting our start node, our list and the document type we want.

            List nodeList = new List();
            AddAllDescendants(new Node(rootNode), nodeList, documentTypeAlias);

So it's time to create magic, our recursive function.

        private void AddAllDescendants(Node CurrentNode, List NodeList, string DocumentTypeAlias) {
            foreach (Node n in CurrentNode.Children) {
                AddAllDescendants(n, NodeList, DocumentTypeAlias);
            }
            if (string.IsNullOrEmpty(DocumentTypeAlias) || CurrentNode.NodeTypeAlias == DocumentTypeAlias) {
                NodeList.Add(CurrentNode);
            }
        }

The first thing we do is for all children, call on our recursive function again. Then we walk up a branch. When we have gone through the entire foreach loop (or if we reach a leaf that has no foreach) we will add our node in the list. Here we make a check to see if node type is the one we are looking for (or if the document is empty and we will add all the nodes). Subsequently, the function returns, and then we walks down the tree again.

When we are back in the Page_Load, we have our List of all nodes of the type we want. From here it is free to do what you like with your list, eg Sort:

            nodeList.Sort(delegate(Node n1, Node n2) {
                return n1.Name.CompareTo(n2.Name);
            });

Download the full solution here: DescendantNodes_NET.zip

Tuesday, November 10, 2009

Blog about Umbraco, CMS and .NET

jango

I'm Fredrik Sewén, a .NET developer. This is my blog which will mainly be tips, tricks and HOWTO's about Umbraco, the best CMS there is.

Category

Latest comments

Powered by Disqus

Subscribe

Rss