使用服務堆棧3.9.21。在IIS 7.5中託管應用程序。使用集成的4.0.30319 ASP.NET應用程序池。帶URL不友好字符的路徑參數
爲了便於說明,讓我們說,我有以下路徑(即由DTO和相應的請求的處理程序支持):
/cars/{id}
有些汽車的ID在他們的字符,我想必須要URL編碼 - 管道,|是其中之一。當我將請求發送到取車與例如ID爲「1 | 2」我得到一個好老500以下堆棧跟蹤:
[ArgumentException]: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.GetFileName(String path)
at ServiceStack.MiniProfiler.UI.MiniProfilerHandler.MatchesRequest(IHttpRequest request) in C:\src\ServiceStack\src\ServiceStack\MiniProfiler\UI\MiniProfilerHandler.cs:line 24
at ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) in C:\src\ServiceStack\src\ServiceStack\WebHost.Endpoints\ServiceStackHttpHandlerFactory.cs:line 153
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我得到這個不管我是否URL編碼管中路徑與否。我怎麼解決這個問題?
更多細節
DTO
using ServiceStack.ServiceHost;
namespace SSUEB
{
[Route("/cars/{id}", "GET")]
public class ById
{
public string Id { get; set; }
}
}
端點
using System.Collections.Generic;
using System.Net;
using ServiceStack.Common.Web;
using Stack = ServiceStack.ServiceInterface;
namespace SSUEB
{
public class Cars : Stack.Service
{
public object Get(ById byId)
{
return new HttpResult(new Dictionary<string, string> {{"id", byId.Id}}, HttpStatusCode.OK);
}
}
}
應用
using ServiceStack.WebHost.Endpoints;
namespace SSUEB
{
public class SSUEB : AppHostBase
{
public SSUEB() : base("ServiceStack toy service", typeof(SSUEB).Assembly)
{
}
public override void Configure(Funq.Container container)
{
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
SetConfig(new EndpointHostConfig { DebugMode = true });
}
}
}
請
這一個:
curl -v -X GET -H "Accept: application/json" http://localhost:80/dealership/cars/123%20456
獲取預期的200迴應:
{"id":"123 456"}
但是這一個:
curl -v -X GET -H "Accept: application/json" http://localhost:80/dealership/cars/123%7C456
導致最初報告的問題。
IIS請求日誌顯示%7C被解碼爲管道,並且%20被解碼(在日誌中至少爲正)。後者導致200(OK)響應,前者 - 500(內部服務器錯誤)。
2012-12-03 22:21:20 127.0.0.1 GET /dealership/cars/123|456 - 80 - 127.0.0.1 curl/7.27.0 500 0 0 5
2012-12-03 22:21:25 127.0.0.1 GET /dealership/cars/123+456 - 80 - 127.0.0.1 curl/7.27.0 200 0 0 1
您可以發佈請求DTO,路由定義和HTTP請求嗎? – mythz
我已添加所需的詳細信息。仍在等待解決方案:D。 – gv0tch0
嘿@mythz - 我發佈了你請求的信息 - 你有機會看看嗎?也許我應該將它作爲github中的問題發佈? – gv0tch0