I am trying to access the Cache in the Application_Start method of Global.asax. I am trying to accdess Context.Cache. When I run the code from visual studio it works just fine but when I run it on the server from IIS I get: Session state is not available in this context. I want to seed some values in the cache when the application starts. How can I get at the cache from Application_Start?
Wow. I found the answer to this. Use the variable HttpRuntime.Cache instead of Context.Cache.
Yes, this changed in IIS7 with the switch to integrated mode. Application_Start executes earlier so the HttpContext is not available.
Visual Studio uses Cassini which differs from full IIS in several ways. Check out the newly released IIS Express which can also be used with Visual Studio. It's a self-contained version of IIS 7.5 so you won't hit problems in production that didn't exist when testing using Cassini.
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