0
votes

Our DNN website is rewriting our product SKU which is part of a Querystring when navigating from a Product Filter Page to a Detailed Product View page.

Unfortunately, some of our products have a forward slash in the SKU for example, BD0002/DSDS

The URL we are navigating to is https://dnndev.me/Product-View/sku/BD0002/DSDS, but DNN would cut off and rewrite the last part of the URL and would result in the following URL: https://dnndev.me/Product-View/sku/BD0002

I did try to add the following Regex code in the SEO settings section of DNN to ignore the re-writing of the page, but it does the same.

sku/(.*)/(.*)

I have also noticed that currently our website writes the sku without the = sign for the querystring. Currently it would be /sku/ and not ?sku= I discovered I can change this when I add |/sku| in the Keep in Querystring Regular Expression.

I have set the URL format to be Advanced in the web.config file. I don't want to change this to HumanFriendly as it breaks our module.

enter image description here

Our product filter page which contains the links to the Product View uses a mustache template with HttpUtility.UrlEncode for QueryStringSKU:

<a href='<%=DetailedPageRedirectLink%>/sku/{{QueryStringSKU}}'>More Info</a>

We then have a Detailed Product View module that listens for the QueryString. I did in the past try to use Encoding and Decoding, but DNN was doing its own thing and ignoring the Encoding and Decoding part so I wrote this crazy part of code that strips out part of the URL that is not part of the SKU.

string rawurlfromrequest = Request.RawUrl;
string checkifquerystringexist = Request.QueryString["sku"];
if(checkifquerystringexist != null)
 {
 var cleanSKU = rawurlfromrequest.Split(new[] { "sku/" }, StringSplitOptions.None)[1];
 decodeprodCode = cleanSKU.Split(new[] { "&" }, StringSplitOptions.None)[0];
 decodeprodCode = decodeprodCode.Split(new[] { "/search" }, StringSplitOptions.None)[0];
 decodeprodCode = decodeprodCode.Split(new[] { "?fbclid=" }, StringSplitOptions.None)[0];
 decodeSKU = HttpUtility.UrlDecode(decodeprodCode);
 }

if (!string.IsNullOrWhiteSpace(decodeSKU) && IsEditable == false)
{
LoadProductDetails(decodeSKU);
}

So I would like to know, how can I only allow DNN to rewrite the first part of the URL and not the SKU part of the querystring when it contains a forward slash?

I found these links: https://www.dnnsoftware.com/answers/disable-friendly-url-for-one-page

https://www.dnnsoftware.com/forums/threadid/542568/scope/posts/how-can-one-turn-off-friendly-urls-url-rewriting-etc-in-dnn-8

1
You need to escape the slashes as %2F.VDWWD
@VDWWD, Thanks, this worked. I had to use uri.EscapedDataString(). I always wanted to know why DNN ignores the Encoding when using Request.QueryString["sku"]; The URL shows that the querystring is encoded, but this method brings it back unencoded with the last part which contains a forward slash cut off.Tig7r

1 Answers

0
votes

I had to escape the query string with uri.EscapedDataString() which will convert the / to %2F as mentioned by VDWWD.

I also discovered that some products contain a space in the SKU which made me decide to use EscapedDataString which will convert a space to %20.

I found this Table with the different Encoding methods on this post useful: URL Encoding using C#

For some reason Request.Querystring['sku'] fetches the unencoded query string even though it is encoded in the URL. This is why I am using Request.RawUrl and stripping the query string from this.