我有一个ASP.NET Core应用程序,我正在部署到Azure,它接受包含冒号(时间邮票)。在IIS/Azure中为ASP.NET Core的URL允许冒号(:)
例如:http://localhost:5000/Servers/208.100.45.135/28000/2017-03-15T07:03:43+00:00
或http://localhost:5000/Servers/208.100.45.135/28000/2017-03-15T07%3a03%3a43%2B00%3a00
URL编码。
此使用红隼(dotnet run
)本地运行时,工作完全正常,但部署到Azure中后,我收到此错误:The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
快速搜索发现,这是由于无效字符的URL中使用,即结肠。传统的解决方法是将此栏目添加到web.config
:
<system.web>
<httpRuntime requestPathInvalidCharacters="" />
</system.web>
然而,增加这个我在Azure上的web.config后,我观察没有变化。我想这是由于ASP.NET Core的托管模式的差异。
这是我目前的web.config
:
<configuration>
<system.web>
<httpRuntime requestPathInvalidCharacters=""/>
<pages validateRequest="false" />
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Server.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
和相关控制头......
[HttpGet]
[Route("{serverIpAddress}/{serverPort}/{approxMatchStartTimeStr}")]
public IActionResult GetMatchEvents(string serverIpAddress, string serverPort, DateTimeOffset approxMatchStartTimeStr)
{
...
}
我怎样才能获得IIS/Azure的,允许在URL中的冒号?
这是一个冒号,而不是逗号,它在RFC 3986的URL的路径部分在技术上是无效的。它们应该是URL编码的('%3A'),它应该阻止该警告出现,并且它们应该在您读取应用程序中的查询字符串参数时会自动解码。 – Adrian
D'oh,'逗号'和'冒号'之间的总脑残。不幸的是,尝试使用URL编码冒号字符的URL会导致相同的错误。使用'/ Servers/208.100.45.135/28000/2017-03-15T07%3a03%3a43%2B00%3a00'进行测试。 –