简体   繁体   English

如何在Moustache模板引擎中使用Server.UrlEncode?

[英]How to use Server.UrlEncode with the Mustache Template Engine?

I am trying to Encode a product SKU on our Product Filter Module. 我正在尝试在产品过滤器模块上对产品SKU进行编码。 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. 当SKU具有正斜杠时,就会出现问题。 For Example, BD1115/35 the code below only detects the first part. 例如,BD1115 / 35下面的代码仅检测到第一部分。

var prodCode = Request.QueryString["sku"];
var decodeprodCode = HttpUtility.UrlDecode(prodCode);

It was suggested that I encode the URL. 建议我对URL进行编码。 Now I am trying to do this with Mustache which is a templating engine. 现在,我正在尝试使用作为模板引擎的Mustache进行此操作。 Look at {{StockCode}} after SKU. 查看SKU后的{{StockCode}}。 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 我看了一下这个问题: 使用Request.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. 更新我已经在后端创建了一个称为QueryStringSKU的新对象,并且在将其替换为Mustache之前对其进行了编码。 So the SKU BDF5555/45 will render in the href as BDF5555%2F45. 因此,SKU BDF5555 / 45将在href中呈现为BDF5555%2F45。

在此处输入图片说明

The problem now comes in when I try to Decode the URL. 现在,当我尝试解码URL时出现问题。 The querystring is now showing BDF5555&45. 现在,查询字符串显示为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) DotNetNuke不知何故正在更改此值或重写它,现在它仍然忽略了45值,它是库存单位(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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM