I'm working on a self-hosted ASP.NET web api-application.
Everything works fine, but now I'm struggling with 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.
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
.
Here's what I'm doing:
Creating a HttpSelfHostConfiguration
Service-Resolvers
& Routes
UserNamePassword-Validator
create new Instance of HttpSelfHostServer with the config
server.OpenAsync().Wait()
Any help how I can tell my server to work with HttpContext.Current
is greatly appreciated!
Cheers!
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.
The HttpContext is only available in the Web-Hosting mode, in which the HttpControllerHandler creates the request.
FYI- I invite you to read the following great articles from Pedro Felix to better understand the different hosting models:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With