Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is HttpContext.Current null during first request to an ASP.Net enabled WCF service?

Tags:

wcf

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.

like image 262
Craig Quillen Avatar asked Oct 12 '10 15:10

Craig Quillen


People also ask

Why is Httpcontext current null after await?

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 .

What is ASP.NET Compatibility Mode?

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.


1 Answers

Turns out this is a bug in the framework that was fixed in 4.0. more info

like image 60
Craig Quillen Avatar answered Sep 21 '22 05:09

Craig Quillen