The Engage Weblog

Getting the current PortalId outside of PortalModuleBase

by Brian Dukes on Friday, December 14, 2007 12:56 PM

It's occasionally tricky/troublesome to pass the current Portald from your DotNetNuke control that inherits PortalModuleBase so that it can be used in your business object logic. A trick that I learned looking at another developer's code recently is to get the current PortalId from PortalController.GetCurrentPortalSettings().PortalId. CurrentPortalSettings is set for every request, so it is always the value that you are looking for.

Hope it helps,

Blogs Parent Separator Brian Dukes
Author
Brian Dukes

Brian Dukes has been working with Engage professionally since 2006, but has been writing code since around 1998. Brian is very passionate about writing code that is easily maintainable, and helping others to do the same. He has been a leader in the DotNetNuke Community, and can often be found speaking at conferences and helping others on twitter, github, and stackoverflow. DNN recognized his community efforts by awarding him the DNN MVP in 2012. Outside of work, Brian spends time with his family, serves Jesus at City Lights Church, as well as supporting social justice, fair trade, local, seasonable food, and international adoption.

2 comment(s) so far...

Anonymous 3/27/2012

This is awesome, thanks for this tidbit!<br /><br />BTW...is there something similar for ModuleID?

 
Brian Dukes 3/27/2012

Ben, there isn't anything similar for module ID, because there's the potential for many different modules to be on the same page. There isn't an easy way to determine which module you're "in" currently, to figure out the ID. I think you're best off getting it from the control that DNN loaded, directly. The closest you could get would be to query the current portal setting's ActiveTab property, and getting all modules on the page.