HttpSelfHostConfiguration

HttpSelfHostConfiguration

本文介绍了HttpSelfHostServer和HttpContext.Current的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个自托管的ASP.NET Web API的应用程序。
一切工作正常,但我现在挣扎的HttpContext

I'm working on a self-hosted ASP.NET web api-application.Everything works fine, but now I'm struggling with HttpContext:

我需要从客户端保存会话信息。
HttpContext.Current 总是空。
所以很明显,我的 HttpSelfHostServer 不与静态的HttpContext级工作。

I need to save session-informations from the client.But HttpContext.Current is always null.So it's obvious that my HttpSelfHostServer don't work with the static HttpContext-Class.

我不明白的事情是:为什么..?
我不能想出一个办法来告诉既不 HtttpSelfHostServer 也不 HttpSelfHostConfiguration 工作HttpContext的

The thing I don't understand is: why..?And I can't figure out a way to tell neither HtttpSelfHostServer nor HttpSelfHostConfiguration to work with HttpContext.

下面是我在做什么:


  1. 创建 HttpSelfHostConfiguration


  • 1.1添加服务解析器&安培; 路线

  • 1.2添加自定义 UserNamePassword-验证

  • 1.1 Adding Service-Resolvers & Routes
  • 1.2 Adding custom UserNamePassword-Validator

创建HttpSelfHostServer的新实例配置

create new Instance of HttpSelfHostServer with the config


  • 2.1 server.OpenAsync()。等待()

  • 2.1 server.OpenAsync().Wait()

任何帮助,我怎么能告诉我的服务器 HttpContext.Current 工作大大AP preciated!
干杯!

Any help how I can tell my server to work with HttpContext.Current is greatly appreciated!Cheers!

推荐答案

您将无法使用的HttpContext在自托管环境。 HttpContext的是由ASP.Net管道,这如果不根据IIS / ASP.Net运行,你就不必设置。

You won't be able to use HttpContext in a self-hosted environment. HttpContext is set by the ASP.Net pipeline, which you won't have if you don't run under IIS/ASP.Net.

HttpContext的是只有在Web托管模式,其中HttpControllerHandler创建要求提供。

The HttpContext is only available in the Web-Hosting mode, in which the HttpControllerHandler creates the request.

FYI-我请你阅读佩德罗菲利克斯下面的大文章,以更好地了解不同宿主模型:

FYI- I invite you to read the following great articles from Pedro Felix to better understand the different hosting models:





  • HTTP processing architecture overview
  • Web-hosting
  • Self-hosting

这篇关于HttpSelfHostServer和HttpContext.Current的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:05