2017-03-15 53 views
2

我有一个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:00http://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中的冒号?

+1

这是一个冒号,而不是逗号,它在RFC 3986的URL的路径部分在技术上是无效的。它们应该是URL编码的('%3A'),它应该阻止该警告出现,并且它们应该在您读取应用程序中的查询字符串参数时会自动解码。 – Adrian

+0

D'oh,'逗号'和'冒号'之间的总脑残。不幸的是,尝试使用URL编码冒号字符的URL会导致相同的错误。使用'/ Servers/208.100.45.135/28000/2017-03-15T07%3a03%3a43%2B00%3a00'进行测试。 –

回答

3

您遇到的问题与路径中的冒号(:)无关,它的确是plus (+) that IIS doesn't like。加号编码为“+”或“%2B”无关紧要。您有两种选择:

  1. 将加号/日期时间偏移从路径移到查询字符串,IIS不介意它。
  2. 将IIS请求过滤模块配置为“allowDoubleEscaping”。

例的web.config:

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

您当前的web.config的system.web节是不相关的ASP.NET核心。

+0

这个伎俩!谢谢! –

+0

“当前web.config的system.web部分与ASP.NET Core无关”,谢谢,但它会是什么? – Arendax

+0

@Arendax这取决于你想要配置什么。在这种情况下,它是system.webServer> security> requestFiltering。对于其他配置,我建议问一个新的SO问题。 – halter73