使用服务堆栈3.9.21。在IIS 7.5中托管应用程序。使用集成的4.0.30319 ASP.NET应用程序池。
为了便于说明,假设我有以下路径(由DTO和相应的请求处理程序支持):
/cars/{id}
有些汽车的ID中包含了我认为必须进行URL编码的字符 - pipe,|,就是其中之一。当我发送请求以获取具有例如“1 | 2”的id的汽车时,我得到一个具有以下堆栈跟踪的好旧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
答案 0 :(得分:1)
我已经看过这个,而且我们无法在ServiceStack中做任何事情,因为它是由ASP.NET生成的预先验证的异常,请参阅{{3}关于如何在IIS / ASP.NET中允许无效字符。
注意:由于它没有通过ASP.NET,因此可以使用ServiceStack的自托管主机,如Scott Hanselman's post所示。