I am trying to Encode a product SKU on our Product Filter Module. The problem I am experiencing is that the Detailed Product View uses the following code to retrieve the appropriate product information. The problem arises when an SKU has a forward slash. For Example, BD1115/35 the code below only detects the first part.
var prodCode = Request.QueryString["sku"];
var decodeprodCode = HttpUtility.UrlDecode(prodCode);
It was suggested that I encode the URL. Now I am trying to do this with Mustache which is a templating engine. Look at {{StockCode}} after SKU. This does not work.
<a href='<%=DetailedPageRedirectLink%>/sku/<%=HttpUtility.UrlEncode("{{StockCode}}")%>' rel="canonical"><img class='responsive productimage' src='{{ProductImage}}' alt='{{StockDescription}}' /></a>
I had a look at this question: Using Request.QueryString, slash (/) is added to the last querystring when it exists in the first querystring
Update I have created a new Object in the Backend which is called QueryStringSKU and I am encoding it before it is replaced with Mustache. So the SKU BDF5555/45 will render in the href as BDF5555%2F45.
The problem now comes in when I try to Decode the URL. The querystring is now showing BDF5555&45.
Somehow DotNetNuke is changing this or rewriting this and now it is still ignoring the 45 value which is part of the Stock Keeping Unit (SKU)
I ended up using this code:
string RawurlFromRequest = Request.RawUrl;
var cleanSKU = RawurlFromRequest.Split(new[] { "sku/" }, StringSplitOptions.None)[1];
var decodeprodCode = cleanSKU.Split(new[] { "&" }, StringSplitOptions.None)[0];