Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUsing Globals.NavigateUrl outside of HttpContextUsing Globals.NavigateUrl outside of HttpContext
Previous
 
Next
New Post
7/21/2016 12:19 PM
 

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.

 
New Post
8/1/2016 5:40 PM
 
So far, I've only been able to get the Tab URL like this:

var catalogUrl = TabController.Instance.GetTab(catalogTabId, portalId).TabPath.Replace("//", "/");

Any other thoughts why NavigateURL or FullUrl generate an exception?
 
New Post
8/1/2016 11:45 PM
 
It has been a very long time since I looked at an issue like this - but my original blog post on this problem may help you to solve the issue:

http://www.ifinity.com.au/Blog/EntryI...

The code it refers to was not part of the DNN Core at that point, but the same basic issue exists : you need to have a Http Context in order to store a PortalSettings object, and the URL code requires a valid PortalSettings object to create a URL. So you can still use the basic overloads to create the URLs but you need to create your own portalSettings object first. It may be more complicated now that there is portal-level language differences.
 
New Post
8/2/2016 9:38 AM
 

I sincerely appreciate the response, Bruce! I'll dig into your solution, but it might not be sustainable because of the localization as you say.

I'll might have to stick with my temporary solution above...

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUsing Globals.NavigateUrl outside of HttpContextUsing Globals.NavigateUrl outside of HttpContext


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out