1. 1 items are tagged with 5.4
  2. 1 items are tagged with Admin
  3. 5 items are tagged with Administration
  4. 1 items are tagged with Award
  5. 1 items are tagged with Bay Area
  6. 2 items are tagged with California
  7. 2 items are tagged with Community
  8. 1 items are tagged with Conference
  9. 1 items are tagged with Contest
  10. 1 items are tagged with Control Panel
  11. 1 items are tagged with Corporation
  12. 2 items are tagged with Daily Tips
  13. 1 items are tagged with Delete
  14. 3 items are tagged with Development
  15. 6 items are tagged with DNN
  16. 1 items are tagged with DNN Corp
  17. 1 items are tagged with DNNUG
  18. 8 items are tagged with DotNetNuke
  19. 1 items are tagged with DotNetNuke Connections
  20. 1 items are tagged with DotNetNuke Friendly URLs
  21. 1 items are tagged with DotNetNuke Tips
  22. 1 items are tagged with Email
  23. 1 items are tagged with Engage Software
  24. 2 items are tagged with Europe
  25. 5 items are tagged with Events
  26. 1 items are tagged with Facebook
  27. 1 items are tagged with Forum
  28. 1 items are tagged with Friendly URLs
  29. 1 items are tagged with Groups
  30. 1 items are tagged with Hard Delete
  31. 1 items are tagged with Host
  32. 1 items are tagged with INETA
  33. 1 items are tagged with Las Vegas
  34. 1 items are tagged with Mandalay Bay
  35. 1 items are tagged with Module
  36. 1 items are tagged with modules
  37. 1 items are tagged with NavigateURL
  38. 1 items are tagged with News
  39. 1 items are tagged with OpenForce
  40. 1 items are tagged with Paris
  41. 1 items are tagged with Personal
  42. 2 items are tagged with Presentations
  43. 1 items are tagged with RadEditor
  44. 2 items are tagged with release
  45. 1 items are tagged with San Francisco
  46. 2 items are tagged with Skinning
  47. 2 items are tagged with Travel
  48. 3 items are tagged with upgrade
  49. 2 items are tagged with upgrades
  50. 2 items are tagged with Users

DotNetNuke Tips? How about DotNetNuke Navigation?

Last Updated Thursday, January 28, 2010 1:13 AM


By: Chris Hammond

What happened to all the DotNetNuke Tips? Life once again happened, life and work. I’ve been travelling a lot the past two months doing onsite DotNetNuke Training, and as of right now that isn’t slowing down!

I’m going to try to get back into the swing of posting tips again, not likely daily, but I will do my best to try to get at least two or three a week cranked out. To start things back off I’m going to tackle a simple, yet commonly overlooked one.

How do you build proper URLs inside of your DotNetNuke modules? There are a million ways you could go about building links, but there are only a few proper ways. Why are there proper ways, and why shouldn’t you just build up all your links manually? Mainly because of the provider model that DotNetNuke supports out of the box. If you haven’t changed out the Friendly URL provider in your DotNetNuke install, you should, we’ll go into details on how in a future post, but for now check out http://www.ifinity.com.au for a great free, and even better paid for version of a URL Provider for DotNetNuke.

The provider model in DNN allows you plug in functionality that can override the way all the URLs are built and rendered. In the old days DotNetNuke URLs used to look like this

1. http://www.dnndaily.com/default.aspx?tabid=353

Every page had a different number. These URLs weren’t ideal because they weren’t easy to remember, and didn’t make sense from a user’s perspective, or from a SEO (search engine optimization) perspective. DotNetNuke built a “Friendly URL” provider, that instead turned the URLs into

2. http://www.dnndaily.com/tabid/353/default.aspx

then in later versions

3. http://www.dnndaily.com/home/tabid/353/default.aspx

and in the most recent releases of DNN the URLs actually become

4. http://www.dnndaily.com/home.aspx

The latter URL being the Friendliest of them all, but the problem with the current friendly URL provider in DNN is that all of the above URLs would work, and return the exact same page/content. The Ifinity URL provider I linked to earlier does it better by doing a 301 redirect for all the “old” URLs and sends them properly to the new URL. This prevents you from having multiple pages on your site with exactly the same content, because while you might know that the above links are all the exact same page out of the database, to a search engine like Google they look like unique pages due to the unique URLs.

So, with that brief primer on some of the various URL formats in DNN (though I didn’t touch on any other querystring parameters) you can start to see how building a URL for a site can be a pain in the rear to do. Well never fear, due to the provider model support in DotNetNuke, you don’t have to worry about what URL provider is in place, or how it is building URLs. You can simply call a method in DNN, with a variety of parameters, and DNN will build the URL for you, actually allowing the provider to build the URL, and passing it back to you in the proper format.

The common method for building URLs is the NavigateURL method found in the DotNetNuke.Common.Globals namespace.

In the previous URL examples all the URLs are pointing to the homepage here on DNNdaily.com, knowing the TabID (page id) of the home page I could simply call the NavigateURL Method and DNN would return me the URL following the format of the provider that is in use. Here’s a quick example of that method (in C#)

   1: var pageUrl = DotNetNuke.Common.Globals.NavigateURL(353);

and the same things in VB.Net

   1: dim pageUrl as string = DotNetNuke.Common.Globals.NavigateURL(353)

The beauty of calling NavigateURL is that you get the properly formatted URL back, on matter what Friendly URL provider is in place. If Friendly URLs are turned off you would get #1 back, if you had the default Friendly URLs turned on you would get #3, if you had Human Friendly URLs turned on you would get back #4.

There are a number of signatures for the NavigateURL method, so if you need to pass querystring parameters in your URLs, perhaps to your custom modules, you can do so with the other formats. Here’s an example of how to pass in two parameters (C#, you can figure the VB.net out on your own, hopefully).

   1: var pageUrlParams = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "", "&qs=1&qc=2");

One thing you might see in the above code is a reference to TabId, I am assuming that you module’s user control is inheriting from PortalModuleBase, if you do that you get access to the current page id (TabId), as well as the current portal’s id (PortalId) and a number of other methods.

One thing you might want to do is link to another page, and you might now know the TabId of that page. If it is safe to assume the Page Name is always going to be the same you can use the following code to lookup the tabid based on the name. (example again in C#)

   1: var tc = new TabController();
   2: TabInfo ti = tc.GetTabByName("PageName",PortalId);
   3: var pageUrl = DotNetNuke.Common.Globals.NavigateURL(ti.TabId);

So there are some of the basics for using the NavigateURL method within DNN to generate URLs that are properly formatted based on the Friendly URL provider in place on the website that your module is installed on. You can play around with the various signatures of NavigateURL to find out other tricks, such as passing in the ControlKey if you have a module that has multiple Control Keys defined in the module controls for a definition.

Hopefully this is a good start to getting back into the swing of my DotNetNuke (somewhat)Daily Tips. If you have any questions feel free to leave a comment here. I’m also hoping to fire up DNNVoice, or some form of a DotNetNuke Podcast again here soon.

Rate this:
Recent Comments
Chris, thanks for the plug. You might also expand on this by showing how developers can add SEO helpful titles into their Urls by using the FriendlyUrlProvider call directly (the one that underlies NavigateUrl when the Friendly Url Provider is 'on'). By passing in a 'cleaned' string of text into the 'pagename' field, then you can get Urls for modules that include descriptive text, just like the Url on this page. I've covered this before at http://www.ifinity.com.au/Blog/EntryId/36/An-open-letter-to-the-DotNetNuke-developers-of-the-world-Please-start-using-the-FriendlyUrlProvider-API-for-custom-page-names As you can see from that Url, the DNN Blog module developers took my advice :)
Posted By: Bruce Chapman on Thursday, January 28, 2010 6:02 AM
I agree that iFinity's URL rewriter toolset rocks! You may want to include a future tip on using the FriendlyUrl Provider. It's iFinity's preferred url rewriting approach.
Posted By: Scott Allender on Thursday, January 28, 2010 9:11 AM