0
votes

We are using Server.URLEncode to change an SKU with a forward slash from BDF5555/45 to BD5555%2F45 in our Href on a button.

enter image description here

When a person clicks on the button the page navigates to another module which has Request.QueryString but DNN is changing the URL.

How can I get the variable decodeprodCode to include the &45 as BDF5555/45? Perhaps DNN is rewriting the URL?

enter image description here

3
This may be a daft question - But because it's a slash "/" - If you do manage to bring it through, won't it be trying look look for a page called "45" which lives under "BDF5555"?Andrew Birks
The SKU is the QueryString argument which is sent to a function in the backend which will retrieve the appropriate product which is on our ERP system. Our other customers use our modules and sometimes they have got a forward slash in the SKU.Tig7r

3 Answers

1
votes

There is a NavigateURL class in DotNetNuke.Common.Globals that will generate a correct url based on a TabID and a lot of overloads.

DotNetNuke.Common.Globals.NavigateURL(TabId)

You can also use querystring parameters

DotNetNuke.Common.Globals.NavigateURL(TabId, ControlKey,"key=value"))
1
votes

DNN by default will re-write querystring values into /key/value format in the URL assuming that it is properly encoded. For example if you have querystring values of sku=1 and productid = 2 the resultant URL will be

https://yoursite.com/Your-Page/sku/1/productid/2

This is done via the FriendlyUrlProvider, but it should not have any impact to your ability to process via Request.Querystring as this is a very, very common practice for passing values into DNN.

Your code to retrieve the value is correct.

0
votes

I ended up using the following code instead of a Request.Querystring.

 string RawurlFromRequest = Request.RawUrl;
 var cleanSKU = RawurlFromRequest.Split(new[] {"sku/"}, StringSplitOptions.None)[1];
 var CleanSKUNoOtherQueryStrings = cleanSKU.Split(new[] {"&"}, StringSplitOptions.None)[0];

The Request.RawURL brings back the URL with the special characters as it is without encoding. As Mitchel Sellers mentioned above, DNN uses the FriendlyURLProvider which rewrites the URL.

For example www.mysite.com/ProductFilter/SKU/BDF5555/45 and not www.mysite.com/ProductFilter/SKU/BDF5555%2F45

The CleanSKU variable will look for SKU/ and split everything on the left as it is set to [1].

After everything has been split on the left, we look for other QueryStrings which we usually add with a & sign. We will split everything on the right by setting it to [0].

This will bring back BDF5555/45 in the backend with a forward slash which we can use to retrieve product information from our ERP system which URLdecode couldn't do.