Is there a DNN URL decode method as it is changing a URL Encode

263 Views Asked by At

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

There are 3 best solutions below

0
On BEST ANSWER

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"))
2
On

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
On

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.