Hi Folks,
In my custom product catalog app built upon DNN CE v8.0.3, I have a Portal Setting to designate the catalog TabId where the products are displayed. I am trying to add the list of products into DNNs search module by generating the URL property using NavigateUrl as such:
public override IList GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate)
{
var searchDocuments = new List();
var urlController = new UrlController();
var portalController = new PortalController();
int catalogTabId = PortalController.GetPortalSettingAsInteger("CatalogTabId", moduleInfo.PortalID, 0);
var portalSettings = new PortalSettings(moduleInfo.PortalID);
var productCatalogController = new ProductCatalogController();
var products = productCatalogController.GetProductCatalog();
foreach (var product in products)
{
...
var searchDocument = new SearchDocument
{
...
Url = urlController.GetProductSeoUrl(product.ProductId, catalogTabId, moduleInfo.PortalID, portalSettings)
...
};
...
searchDocuments.Add(searchDocument);
}
return searchDocuments;
}
The search method above calls another method that gets the SEO friendly URL setup in the database like this:
public string GetProductSeoUrl(int productId, int catalogTabId, int portalId, PortalSettings portalSettings)
{
if (productId > 0)
{
var catalogUrl = Globals.NavigateURL(catalogTabId, portalSettings, "");
...
}
return null;
}
Problem is that the NavigateURL Method doesn't seem to work outside of HTTP Context. I debugged and can see that the catalogTabId and portalSettings params are populated, but I get this error:
Message:Object reference not set to an instance of an object.
StackTrace: at DotNetNuke.Entities.Urls.AdvancedFriendlyUrlProvider.FriendlyUrlInternal(TabInfo tab, String path, String pageName, String portalAlias, PortalSettings portalSettings) at DotNetNuke.Entities.Urls.AdvancedFriendlyUrlProvider.FriendlyUrl(TabInfo tab, String path, String pageName, PortalSettings portalSettings) at DotNetNuke.Common.Globals.NavigateURL(Int32 tabID, Boolean isSuperTab, PortalSettings settings, String controlKey, String language, String pageName, String[] additionalParameters) at DotNetNuke.Common.Globals.NavigateURL(Int32 tabID, PortalSettings settings, String controlKey, String[] additionalParameters) at AdoreCatalog.Components.UrlController.GetProductSeoUrl(Int32 productCategoryId, Int32 homeTabId, Int32 catalogTabId, Int32 portalId, PortalSettings portalSettings) in UrlController.cs:line 97 at AdoreCatalog.Components.FeatureController.GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) in FeatureController.cs:line 70 at DotNetNuke.Services.Search.ModuleIndexer.IndexSearchDocuments(Int32 portalId, ScheduleHistoryItem schedule, DateTime startDateLocal, Action`1 indexer)
I also tried using the line below in GetProductSeoUrl but it returned an empty value:
var catalogUrl = tabController.GetTab(catalogTabId, portalId).FullUrl;
Hopefully someone can point me in the right direction on how to get the page's friendly URL from the TabId.