重现的步骤:
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。