我正在处理自托管的ASP.NET Web API应用程序。 一切工作正常,但现在我挣扎着HttpContext
:HttpSelfHostServer和HttpContext.Current
我需要保存来自客户端的会话信息。 但HttpContext.Current
始终为空。 所以很明显,我的HttpSelfHostServer
不适用于静态HttpContext类。
我不明白的是:为什么......? 而我不知道HtttpSelfHostServer
和HttpSelfHostConfiguration
与HttpContext
一起工作的方式。
下面是我在做什么:
创建
HttpSelfHostConfiguration
- 1.1添加
Service-Resolvers
&Routes
- 1.2添加自定义
UserNamePassword-Validator
- 1.1添加
创建HttpSelfHostServer的新实例配置
- 2.1
server.OpenAsync().Wait()
- 2.1
任何帮助,我怎么能告诉我的服务器HttpContext.Current
工作是非常感谢! 干杯!
也许需要'AspNetCompatibility':http://stackoverflow.com/questions/5904313/access-httpcontext-current-from-wcf-web-service – mellamokb 2012-07-05 15:43:49
嗨mellamokb。谢谢,但是如果我使用aspNetCompatibelity-Mode,我仍然需要一个IIS,这是我想避免的。 – Richard 2012-07-06 09:42:34
另请注意,我发布的链接中的第二个答案指的是OperationContext中提供的许多相同的信息。你究竟需要从HttpContext中获得什么? – mellamokb 2012-07-06 13:18:28