· 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 Ifinity URL Provider for a great free, and even better paid-for version of a URL Provider for DotNetNuke.

The provider model in DNN allows you to 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.example.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 an SEO (search engine optimization) perspective. DotNetNuke built a “Friendly URL” provider, that instead turned the URLs into:

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

Then in later versions:

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

And in the most recent releases of DNN, the URLs actually become:

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

How to Build URLs in DotNetNuke

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, 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.

Knowing the TabID (page id) of the home page, you can simply call the NavigateURL method and DNN will return the URL following the format of the provider that is in use.

Example in C#:

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

Example in VB.Net:

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

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

Passing QueryString Parameters

There are a number of signatures for the NavigateURL method, so if you need to pass query string parameters in your URLs, perhaps to your custom modules, you can do so with other formats.

Example in C#:

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 your 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.

Finding the TabID of Another Page

One thing you might want to do is link to another page, and you might not 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 look up the TabId based on the name.

Example in C#:

var tc = new TabController();
TabInfo ti = tc.GetTabByName("PageName", PortalId);
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 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 »