I have some WCF services that are hosted by IIS with ASP.Net compatibility turned on.
I have the following in my web.config:
< serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
And my service class is decorated with the following:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
For some weird reason, the HttpContext.Current is null for the first request after the web app starts up. The HttpContext.Current is not null for following requests as expected.
Does anyone have an idea why it isn't working for the very first request?
The call to HttpContext.Current is from within a custom UserNamePasswordValidator class I wrote to check creds stored in the database.
Current as a thread-static variable will no longer resolve to the appropriate value. Now, based on the synchronization context, it could actually be forced to go back to the same thread after the await but I'm not doing anything fancy in my test. This is just a plain, naive use of await .
ASP.NET compatibility mode allows WCF services to use ASP features such as identity impersonation. It is enabled at the application level through the Web. config file and cannot be overridden by Web. config files nested in the application.
Turns out this is a bug in the framework that was fixed in 4.0. more info
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