【问题标题】:How to use Server.UrlEncode with the Mustache Template Engine?如何将 Server.UrlEncode 与 Mustache 模板引擎一起使用?
【发布时间】:2018-09-17 09:36:15
【问题描述】:

我正在尝试在我们的产品过滤器模块上对产品 SKU 进行编码。 我遇到的问题是详细产品视图使用以下代码来检索适当的产品信息。当 SKU 有正斜杠时,就会出现问题。例如,BD1115/35 下面的代码只检测第一部分。

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

有人建议我对 URL 进行编码。现在我正在尝试使用模板引擎 Mustache 来做到这一点。查看 SKU 后的 {{StockCode}}。这不起作用。

 <a href='<%=DetailedPageRedirectLink%>/sku/<%=HttpUtility.UrlEncode("{{StockCode}}")%>' rel="canonical"><img class='responsive productimage' src='{{ProductImage}}' alt='{{StockDescription}}' /></a>

我看过这个问题:Using Request.QueryString, slash (/) is added to the last querystring when it exists in the first querystring

更新 我在后端创建了一个名为 QueryStringSKU 的新对象,并在将其替换为 Mustache 之前对其进行编码。因此 SKU BDF5555/45 将在 href 中呈现为 BDF5555%2F45。

当我尝试解码 URL 时,问题就出现了。查询字符串现在显示 BDF5555&45。

DotNetNuke 正在以某种方式更改或重写它,现在它仍然忽略作为库存单位 (SKU) 一部分的 45 值

【问题讨论】:

    标签: c# query-string encode mustache


    【解决方案1】:

    我最终使用了这段代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 2015-10-17
      • 2012-02-13
      相关资源
      最近更新 更多