0

I am writing an e-commerce website using DotNetNuke, and I have ran into a problem. For example I have a module on a page that has a URL of mydomain/productType/product-pages. What I would like is to pass a query string to this page with the item number of product (lets say its name is bacon). And when page loads, I would like both the breadcrumbs and URL(at browser) to read mydomain/productType/product-pages/bacon. I have researched how to change the page title, meta description, and all that already and have tested and it works - but just cannot find a way to modify the URL. I don't even know if this is possible. My goal is to not create all the pages for products within DNN, because this will change over time. I'm pretty sure I can create a page within DNN each time page is passed the query string which is a possibility, and another possibility would be have my other module create the link like it should read(just no page created) and DNN would just land on product-pages just add the /bacon? But I would rather just spoof the URL if possible. Any suggestions or help would be greatly appreciated, and Thanks for reading.

Below is code snippet for changing the title and description:

protected void Page_PreRender(object sender, EventArgs e)
   {
      string pageName = Request.QueryString["pageName"];
      if (!string.IsNullOrEmpty(pageName))
        {

            Page.Title = pageName;
            Page.MetaDescription = "Blah";
            Page.MetaKeywords = "Stuff,more stuff";
            var url = HttpContext.Current.Request.RawUrl;
            //Page.ResolveUrl(url + "/" + pageName);//this didnt work 
            //below is another way compared to top
            //DotNetNuke.Framework.CDefault myPage = new 
            DotNetNuke.Framework.CDefault();
            //myPage = (CDefault)this.Page;
            //myPage.Title = "This is the new title";


       }
   }
duerzd696
  • 304
  • 1
  • 8

1 Answers1

0

The best way to manipulate the URLs for your custom module is by building a Extension URL provider. But you need to reverse your thinking about the problem. You don't want an ugly URL with a querystring argument to change into another URL. Rather, you start with the desired URL path and you want that to resolve or be "written" as the ugly querystring URL under the covers. That's what a Extension URL provider does.

I have a tutorial on DNNHero.com that walks you through it.

https://www.dnnhero.com/video/introduction-and-url-rewriting-basics

Unfortunately, that video is behind a paywall. (IMHO, it is worth the cost even for this one tutorial and code.)

You can also check out the blog:

https://www.dnnsoftware.com/wiki/extension-url-providers#:~:text=An%20Extension%20URL%20Provider%20is,and%20logic%20to%20be%20implemented.

Fix It Scotty
  • 2,852
  • 11
  • 12
  • @ Fix It Scotty Can the code just be written within the event I have posted above? Why do I need a provider - seems like allot of work to me. – duerzd696 May 06 '22 at 15:00
  • I am not aware of a method on the server or client side for just changing the URL. For SEO purposes, you need a server-side way of resolving your "pretty" URLs. The tutorial I made shows how to build a relatively simple URL rewriter packages with your module. – Fix It Scotty May 06 '22 at 18:40