· Chris Hammond
Last Updated

DotNetNuke Tips? How about DotNetNuke Navigation?

Discover the evolution of DotNetNuke URLs and learn how to build proper URLs within your modules using NavigateURL method in this informative post.

Discover the evolution of DotNetNuke URLs and learn how to build proper URLs within your modules using NavigateURL method in this informative post.

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 https://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. https://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

  1. https://www.dnndaily.com/tabid/353/default.aspx

then in later versions

  1. https://www.dnndaily.com/home/tabid/353/default.aspx

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

  1. https://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.

Share:
Back to Blog

Related Posts

View All Posts »