2017-03-15 57 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