解码动作参数时,Ubuntu和Windows的行为有所不同

时间:2018-03-19 18:41:41

标签: c# asp.net-core

重现的步骤:

GET请求(通过Postman或类似):

http://localhost:56024/api/controllername/https%3A%2F%2Fsomething.com

url = encodeURIComponent('http://something.com')。这会产生url = http%3A%2F%2Fsomething.com

也就是说,GET请求被分解为:

'http://localhost:56024/api/controllername/' + encodedParameter

ASP.NET Core API控制器:

[Route("api/controllername")]
public class ControllernameController : Controller
{
    [HttpGet("{*url}")]
    public IActionResult MyAction(string url)
    {
        // Windows (test): url == "http:/something.com" <= Wrong
        // Ubuntu (prod): url == "http%3A%2F%2Fsomething.com" <= OK
    }   
}

Projectname.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  ...     

</Project>

如何修复Windows上的行为?

我在Windows 10上使用Visual Studio Community 2017版本15.5.7。

0 个答案:

没有答案