Why is HttpContext.Current null when I first request a WCF service with ASP.Net support?

I have some WCF services that host IIS with ASP.Net support enabled.

In my web.config there is the following:

<serviceHostingEnvironment aspNetCompatibilityEnabled = "true" / ">

And my service class is decorated with the following:

[AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

For some strange reason, HttpContext.Current is null for the first request after starting the web application. HttpContext.Current is not null for the following requests, as expected.

Does anyone have an idea why it is not working for the very first request?

The HttpContext.Current call is made from the user class UserNamePasswordValidator, which I wrote to verify the accounts stored in the database.

+6
wcf
source share
2 answers

It turns out this is a bug in the structure that was fixed in 4.0. more details

+1
source

If you use IIS 7.0 integrated mode to host your HttpContext.Current application, it may not be initialized in Application_Start , so if you try to access it, it will work.

0
source

All Articles