Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error accessing the Cache in the Application_Start method of Global.asax

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?

like image 358
minty Avatar asked Nov 18 '25 22:11

minty


2 Answers

Wow. I found the answer to this. Use the variable HttpRuntime.Cache instead of Context.Cache.

like image 164
minty Avatar answered Nov 21 '25 12:11

minty


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.

like image 24
Joel Fillmore Avatar answered Nov 21 '25 12:11

Joel Fillmore