双重转义和+符号

问题描述 投票:0回答:1

使用.NET Core 2.1和双重转义只是'+'符号从框架而不是一次非转义两次。我的代码如下:

[HttpGet("article/{productCode}/movements/{movementId:int}")]
public async Task<IActionResult> MovementGet(string productCode, int movementId)
{
productCode = WebUtility.UrlDecode(productCode);
//... rest of the code ...

}

我在项目文件夹中创建了一个web.config,以便为IIS / IISExpress启用双重转义

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering allowDoubleEscaping="true"/>
    </security>
  </system.webServer>
</configuration>

要求产品代码FMB+FTR97/MB06双重逃避将是http://localhost:4198/api/v1/warehouse/article/FMB%252BFTR97%252FMB06/movements/1946127

异常(至少对我而言)是fw解析的产品代码,因为我收到:FMB+FTR97%2FMB06而不是FMB%2BFTR97%2FMB06,当我调用WebUtility.UrlDecode(productCode)时,我得到的FMB FTR97/MB06错了。

起初我虽然是一个IIS问题,但我尝试使用ASP.NET 4.6(使用HttpUtilities.UrlDecode)相同的代码,它按预期工作,我得到了FMB%2BFTR97%2FMB06

我是以错误的方式使用web.config吗?

c# asp.net-core escaping
1个回答
0
投票

如果有人有兴趣,我在github上的问题得到了答复:https://github.com/aspnet/Home/issues/3580

更新我解决了问题。要获得正确的编码和解码,请使用Uri.EscapeDataString(productCode)Uri.UnescapeDataString(productCode)进行双重转义

© www.soinside.com 2019 - 2024. All rights reserved.