Archive for tag: umbraco

Blog4Umbraco database cleanup

I recently set about consolidating the tags I use on my blog posts to make the category listing and tag cloud smaller and more user friendly. In addition reducing the the number of tags and making them more generic means the remaining pages will contain more content and should rank better on the search engines.

Having completed the cleanup in the umbraco client I then turned my attention to the database to see what old tag information remained.

The following SQL Command will show you the unused tags in your database.

select * from cmstags where id not in (select tagid from cmsTagRelationship)

select * from cmstags where id not in (select tagid from cmsTagRelationship)

To delete these unused tags simply run:

delete from cmstags where id not in (select tagid from cmsTagRelationship)

If you would like to remove a tag that is still associated with one or more posts simply run:

delete from cmsTagRelationship where tagId in (select id from cmsTags where tag = 'OLDTAG')

which will delete the relationship and then:

delete from cmsTags where tag = 'OLDTAG'

Which will remove the tag itself.

@ismailmayat has also created an umbraco package for tag management that can be found at http://our.umbraco.org/projects/tagmanager.

Programmatic document creation in umbraco

The umbraco API is extremely powerful and can easily be used to create content pages via code.  Recently I created an umbraco website where I needed to be able to take data from a genealogy file and create a page on the site for each individual in the file.

To create a document via code is fairly simple, first add the following two references to your code:

using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;

The code to create a document can be seen here:

// Get a reference to the docType 'Family' is my docType Alias
DocumentType dt = DocumentType.GetByAlias("Family");
    
// User 0 is the admin user
User author = umbraco.BusinessLogic.User.GetUser(0);

// Create a document with a name, a type, an umbraco user, and the ID of the 
// document's parent page. 
Document doc = Document.MakeNew("New Page Name", dt, author, 1376);
   
// Set document properties
doc.getProperty("pageTitle").Value = "";
doc.getProperty("metaKeywords").Value = "";
doc.getProperty("bodyText").Value = "";

// Prepare for publishing 
doc.Publish(author);

// Publish the document
umbraco.library.UpdateDocumentCache(doc.Id);
return doc.Id;

This code can then be put into a webservice and copied onto your umbraco site.  It can then be called from any application or system that needs to create content on your site.

Rewrites are not Redirects

One of the best URL rewriting packages for the .Net platform is URLRewriting.net.  This excellent package is shipped with many open-source applications, including umbraco, however a lot of developers often fail to realise that there is a big difference between URL rewriting and URL redirection (both of which this package can do).

With URL rewriting the client browser requests Page A from the server.  The server then looks at it's configuration file and returns the content for a different page. i.e. Page B.  In this scenario the client has requested Page A and has received content which it believes came from Page A.  It knows nothing about the existence of Page B.

With URL redirection however the client browser requests Page A from the server.  The server then returns a 301 (permanent) or 302 (temporary) response to the client along with the new page name (Page B).  The client browser then proceeds to make another request to the server, this time for Page B.

From an SEO perspective, using permanent URL redirection means the search engines should index the correct destination URL, as effectively the server is saying Page A doesn't exist, use Page B instead.

With URL rewriting however it is possible that the server can index both Page A and Page B.  To see this in action, google for the term site:bayshield.com.  In the results you will see links for both /blog?filterby=umbraco and /blog/tag/umbraco.

It is important to note that this is not best practice!  Your site will not be easier to find because Google has 'indexed' two versions of the same page.  So next time you use URLRewriting.net be sure to look at the documentation and determine if it is URL Rewriting or URL Redirection you are after.

Using the ASP.Net Login control in umbraco

The following is a step by step guide to using the ASP.Net login control in umbraco.

Step 1

Create a new DocType and associated template called Login Example.

Login Example Screen 1

Step 2

Go to the new Login Example template and add the form tag and login control code as shown below.

Screen shot 2010-01-08 at 15.53.49

Step 3

Now go to the content node and create a page called Login using the 'Login Example' docType.  If 'Login Example' docType is not available ensure you have it as an allowed child node of the parent docType.

Login Example Screen 3

Step 4

Now you can view your new login page!Login Example Screen 4

Step 5

To use your login page you will need to go to the Members section and create a member type.  This must be created before you try and create your first member.  Also, if you plan to use the createUserWizard control you will need to update your web.config as per my previous post to reference this member type.

Login Example Screen 5

Step 6

Now you can create your user.

Login Example Screen 6

Step 7

The final step in the whole process is to secure the portion of the site that you want to be members only.  To do this go to the content node you want to secure, right click and choose 'Public Access'  This will then give you the option to choose 'User Based' or 'Role Based' security.  Once you select one of these options you will then be prompted to choose your Login page (just select the login page node from the tree) and the error page which will be displayed if a user is valid, but doesn't have sufficient privileges.

Using .Net Membership controls with umbraco

The asp.net membership controls will work almost straight out of the box with the umbraco membership provider with the exception of the CreateUserWizard control which requires a small change to be made to your web.config file.

There is an umbracoMembershipProvider section in the web.config file that contains a key called 'defaultMemberTypeAlias'.  The value in this key must correspond to a MemberType that exists in your Members section.

When the createUserWizard control runs it will create the user with the details supplied and then try and assign them to the memberType in the key.  If you haven't changed this value to match a real memberType you will receive an error and the user won't be created.

Creating a package in Umbraco

If you find yourself continually performing the same tasks when creating a new umbraco site then you should consider creating an umbraco package.  As the name suggests an umbraco package allows you to group all your umbraco files together so they can be easily installed on a new umbraco site.

Step One

Creating a package in umbraco is quite easy.  First go to the developer section in umbraco and right click the 'Created packages' node and enter the new package name.

Create package node

Step Two

Enter the package properties (the real fun is on the next three tabs)

Initial Package Creation Screen

Step Three

Next go to the package contents screen and select any content, document types, templates etc... that you would like included in your package.

Package Screen 2

Step Four

The 'Package Files' tab allows you to add assemblies, images and scripts to your package.

Package Screen 3

Step Five

The final step is to add any package actions that your package requires.  There is a good guide to package actions that can be found here.

Screen shot 2010-01-04 at 21.14.35

Finally...

Now all that is left to do is to publish your package and upload it to our.umbraco.org for the community to share (after testing of course!).

Optimising the new Blog4Umbraco package for SEO

The new blog4Umbraco package is an excellent choice for anyone wanting an umbraco powered blogging site.  There are however a couple of small changes that can be made to improve the rankings and click throughs to your site.

The first change I have made is to include a new tab on each DocType called "SEO".  On this tab I have added two items, Page Title and Meta Description.

Screen shot 2010-01-02 at 15.08.14

When Google (or any other search engine for that matter) indexes your site, they typically (but not always) use the value inside the meta description tag as the description shown in the search result, however when no meta description is supplied the search engine will choose what it considers to be the most relevant text.

Search Result

In the example above you can see that because I didn't have a Meta Description tag, Google chose the text from the most recent blog to show in the search result.  There are two potential issues here.  Firstly if you blog on a variety of topics as I do, the description shown may not be related to what the user was searching for, meaning they might skip over your search result to another seemingly more relevant result.

Secondly if you want your page to rank for a particular topic (such as umbraco), having a specific description related to the topic will act as a strong indicator to Google about the purpose/context of the page.

Simply add the following code to the BlogMaster template and add the metaDescription field to your doctypes and you are all set.

<umbraco:Item field="metaDescription" runat="server" insertTextBefore="&lt;meta name=&quot;description&quot; value=&quot;" insertTextAfter="&quot; /&gt;"></umbraco:Item>

SEO Change #2

The other change I like to make is to the Archive page, or more importantly the BlogFullArchive.xslt file.

Find the line that says:

<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a> <br/>

and then insert the following after:

<xsl:value-of select="data [@alias = 'metaDescription']"/><br />

This helps put a little more content (and context) on the Archive page and is more likely to make it rank strongly.

Google Sitemap

Finally don't forget to add a Google Sitemap to your site and submit it in webmaster tools.

NetTiers, Codesmith and Umbraco

One of my least favourite development tasks is writing data access code.  Luckily a couple of years back a friend introduced me to the open source NetTier Application Framework. As the name would suggest NetTiers is an application framework, however in its simplest form it is a set of templates which allow you to generate a complete data access layer based on your SQL Server database.

To execute the templates however you will need a tool.  I use CodeSmith which isn't open source but costs under $100 (there is a 30-day free trial available).  Whilst this may seem steep, the time saved in writing data access code will easily pay for this with just one application.

In order to use the NetTiers framework with umbraco, simply write your .Net user controls as you normally would and reference the generated NetTiers classes.  The controls can then be built and uploaded to umbraco as normal.

The final step is to add a number of items into your umbraco web.config file.  These settings will change depending on the options you select in CodeSmith, so the simplest way to get the correct settings is to choose the "Generate Website" option in CodeSmith and then copy the settings from the generated web.config (after which you can delete the website).

 

Creating a Google Sitemap in umbraco

One of the must do tasks for any webmaster is the creation and submission of a sitemap to Google. Submitting a sitemap doesn't guarantee that all the pages in your site will be indexed, however it does make it easier for the search engines to at least find your content, which is particularly important if your site is not structured in a SEO friendly manner.

There are a number of packages in the umbraco forum for creating Google sitemaps, however in this article I will show you how to make your own which we will modify in future articles to form the basis of a News Sitemap and a Video Sitemap.

The google article on creating and submitting sitemaps can be found here.

Step 1

The first step in umbraco is to create a new document type and matching template which we will call "Google Sitemap".  Add one new property to this doc type with an alias of umbracoNaviHide and use the "True/False" datatype.

Step 2

Create a new XSLT file called "Google Sitemap" and paste the following code.  Please note that this code initially came from someone in the umbraco community, however I don't know who so I can't reference them here, also the domain name is hard coded in two locations below which you will need to update.

<xsl:template match="/">
<!-- rendering first level node -->
<url>
<loc>/</loc>
</url>

<xsl:call-template name="drawNodes">  
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="drawNodes">
<xsl:param name="parent"/>

<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or      (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and      umbraco.library:IsLoggedOn() = 1)">

<xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and         @level <= $maxLevelForSitemap]">
<url>
<loc><xsl:value-of select="umbraco.library:NiceUrl(@id)"/></loc>
</url>
<xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and        @level <= $maxLevelForSitemap]) > 0">  
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>

Step 3

Open the Google Sitemap template created in step 1 and paste in the following code.

<%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %><asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><?xml version='1.0' encoding='UTF-8'?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><umbraco:Macro Alias="GoogleSitemap" runat="server"></umbraco:Macro></urlset></asp:Content>

Step 4

The final step is to go into the content tree and create a new file.  This can be called anything you want, however you will need to note the filename so you can submit it through webmaster tools.  If you don't have the option of "Google Sitemap" as a valid child node, check to ensure that the parent document type allows the "Google Sitemap" doctype as a child node.

Umbraco Beginners Tips

I have been using umbraco extensively for the past year and have benefited greatly from the advice and tips from the umbraco community.  In the spirit of Christmas I wanted to start my new blog by giving something back, and hopefully help some umbraco new comers in the process!

Clean URLs

Despite being a huge fan of .Net, I still prefer my URL's to be clean and not have the .aspx extension. Luckily umbraco makes this extremely easy to achieve in about two minutes.  To start with open the web.config file and look for the umbracoUseDirectoryUrls key and set the value to True.

Secondly open the IIS Manager and go to the application configuration tab.

App Config for Extensionless URLs

You need to insert a wildcard map to allow .Net to process files regardless of the file extension.  I usually open the .aspx entry in the top box and copy the executable path and paste it when I create the wildcard entry.  The only thing to note is that when you create the wildcard entry you need to uncheck the box that says 'check file exists'.

404 - Page not found

It is sometimes easy to overlook the error page that users see, however in umbraco it is very easy to setup.  The first step is to create a page in umbraco that you would like users to see when a 404 is encountered.  Once this is done look at the properties tab for the page and take note of the page id.

Page ID in umbraco

Next open the umbracoSettings.config file in the config folder.  In the file you will find a error404 tag.  Simply replace the default page ID with your page ID and you are done!