【发布时间】:2016-01-08 12:34:07
【问题描述】:
我们使用
HostContext.RawHttpHandlers.Add(action)
开始时间测量和
m_appHost.PreRequestFilters.Insert(0, action) // we want to be the first filter executed
停止时间测量。我们按顺序向服务器发送请求(使用 IIS Express 开发服务器在 localhost 上运行)并观察这两个操作之间的时间。有时它低至几毫秒,但通常会上升到几百毫秒。轻量级 GET 请求也会发生这种情况。
根据https://github.com/ServiceStack/ServiceStack/wiki/Order-of-Operations
- HostContext.RawHttpHandlers 在执行任何其他操作之前执行,即返回任何 ASP.NET IHttpHandler 完全绕过 ServiceStack 并改为处理您的自定义 IHttpHandler。
- 如果请求与任何现有路由都不匹配,它将在 IAppHost.CatchAllHandlers 中搜索匹配项
- IAppHost.PreRequestFilters 在 Request DTO 被反序列化之前被执行
我们还挂钩到 CatchAllHandlers 以确保它不会被调用:
m_appHost.CatchAllHandlers.Insert(0, action)
我们使用如下属性在 AppHost 中注册路由:
typeof(HelloRequestDTO).AddAttributes(new RouteAttribute("/hello/{Name}", "GET"));
知道什么会在 RawHttpHandler 之后和 PreRequestFilters 之前导致这种延迟吗?
ServiceStack 版本是 4.0.50。
【问题讨论】:
标签: c# asp.net request servicestack delay