Craig Quillen
Craig Quillen

Reputation: 2057

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

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.

Upvotes: 6

Views: 1795

Answers (2)

Craig Quillen
Craig Quillen

Reputation: 2057

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

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

If you are using IIS 7.0 integrated mode to host your application HttpContext.Current might not be initialized in Application_Start so if you are trying to access it there it will crash.

Upvotes: 0

Related Questions