If you or your client needs to be able to create short urls or links to other sites without wanting to add it as a redirect in the web config, then this is the post for you. You can create them as umbraco pages that act as fast links or redirects.
Firstly, you need to create a template for the document type to use.
I normally create on called 'FastLink'.
Here is the code I use for the template:
Layout = null;
string linkUrl = "";
var linkItem = CurrentPage.linkTarget.First;
linkUrl = linkItem.link;
Now you need to create a document type, in this case I call it 'Fast Link'. Choose the Fast Link template you just created.
I would then normally create a tab called 'Information'. Once you have created the tab, you can then create a Related Links property called 'Link Target'. The alias for this property should automatically be set to 'linkTarget'
Make sure you choose the Information tab for this property to appear in. Once this document type is saved, you are ready to use it in your site.
To be able to add it into the structure of your site, you need to edit the document type that you would like to allow it under, i.e. your 'Home' document type. Go to the structure tab and in the allowed child nodes check box list, choose 'Fast Link'. Then hit save.
You can now create a Fast Link in the site under the home node, or whichever you set it to. When you create it, you will need to add a row to the Link Target field, by entering a caption, choosing an internal page or inputting an external url and then tick whether or not you want it to open in a new tab. (This will come in handy when using it in a menu).
Save the row and Save and Publish the document.
Next visit the url of the item you created e.g. http://www.mysite.com/test/ and it should redirect you to the page or external address you chose.
To finish this off you can use these fast links in your site menu.
Here is an example Partial which generates a site menu from the pages in your site with a simple ul > li structure:
var homePage = CurrentPage.AncestorsOrSelf(1).First();
@helper RenderChildren(dynamic parentPage)
var children = parentPage.Children.Where("Visible").Where("excludeFromTopNavigation != true && documentTypeAlias != \"Xmlsitemap\"");
if(children != null && children.Any() && children.Count() > 0)
foreach(var page in children)
string linkUrl = page.Url;
string linkTarget = null;
string linkCaption = page.Name;
@if(page.documentTypeAlias == "FastLink" && page.HasValue("linkTarget"))
var linkItem = page.linkTarget.First;
linkUrl = (bool)linkItem.isInternal ? Umbraco.NiceUrl(linkItem.Value<int>("internal")) : linkItem.link;
linkTarget = (bool)linkItem.newWindow ? "_blank" : null;
linkCaption = linkItem.caption;
<a href="@linkUrl" target="@(!String.IsNullOrEmpty(linkTarget) ? linkTarget : null)">@linkCaption</a>
Notice that when it identifies the document as a Fast Link, it gets the caption, target and url from the first row in the link target field. This means that when the fast link is rendered in a menu, the page can open in a new tab if the new window value was set to true.
Follow along with this video to get you started with Umbraco
This post shows you how you can ignore a file in git locally without ignoring it from the repository…Read Post
This post shows you how you can get the name of the picked item in Nested Content or Stacked Content…Read Post
In this post I share my approach to using source control for my Umbraco website source code and medi…Read Post
This post will show you how to solve the error "Could not load file or assembly 'Microsoft.CodeDom.P…Read Post