DotNetNuke, ASP.NET, Web Development Blog

Programmatically determining the site's Fully Qualified URL and Path in DotNetNuke

There are hundreds of different functions and variables available through DotNetNuke, ASP.NET, and HTTP which can give you a variety of variations on your sites URL. I often find myself needing one variation or another as I'm building one application or another. The problem is, I have yet to find a clean and consistent way to get at the site's root or fully qualified URL regardless of whether the site is in a virtual directory (i.e. or, for sites with virtual directories For DotNetNuke, I'm now using the following...


For the ApplicationPath:
DotNetNuke.Common.Globals.ApplicationMapPath.Replace("Portals\_default\", "")

For the Fully Qualified Url (or root URL or Base URL):
1.) First, determine the relative url for the page or file you're wanting. You can use either DotNetNuke.Common.Globals.ResolveURL() or one of the many NavigateURL() functions

2.) Next, add the following function somewhere in your class or a utility class:

Public Shared Function GetFullyQualifiedURL(ByVal s as string) As String
   Dim Result as URI = New URI(HttpContext.Current.Request.Url, s)
   Return Result.ToString
End Function

3.) Then Call GetFullyQualifiedURL and pass in the RelativeURL.


Here's most of the variables and functions I've found and examples of what they return for my local DotNetNuke Site:

DotNetNuke.Common.Globals.HostMapPath: C:\WebSites\DNN441\Portals\_default\
DotNetNuke.Common.Globals.HostPath: /DNN441/Portals/_default/
DotNetNuke.Common.Globals.ApplicationMapPath: C:\WebSites\DNN441
DotNetNuke.Common.Globals.ApplicationPath: /DNN441
DotNetNuke.Common.Globals.ApplicationUrl: ~/Default.aspx?tabid=56
NavigateURL: /DNN441/ModuleTesting/Articles/tabid/56/Default.aspx?ctl=~/Default.aspx
DotNetNuke.Common.Globals.glbApp: ~/Default.aspx?tabid=56
PortalSettings.HomeDirectory: /DNN441/Portals/0/
PortalSettings.HomeDirectoryMapPath: C:\WebSites\DNN441\Portals\0\
ResolveURL: /DNN441/Portals/0/aspnet.gif
Request.PhysicalPath: C:\WebSites\DNN441\Default.aspx
Request.ApplicationPath: /DNN441
Request.PhysicalApplicationPath: C:\WebSites\DNN441\
MapPath: C:\WebSites\DNN441\DesktopModules\Articles\Templates\Default.aspx
RawURL: /DNN441/ModuleTesting/Articles/tabid/56/ctl/Details/mid/374/ItemID/1/Default.aspx
Request.Url.AbsoluteUri: http://localhost:4471/DNN441/Default.aspx?TabId=56&ctl=Details&mid=374&ItemID=1
Request.Url.AbsolutePath: /DNN441/Default.aspx
Request.Url.LocalPath: /DNN441/Default.aspx
Request.Url.Host: localhost
Request.Url.PathAndQuery: /DNN441/Default.aspx?TabId=56&ctl=Details&mid=374&ItemID=1


Leave a Comment
Email: (not displayed)

Enter the code shown above:

Return to previous page