locked
Application state and HttpRuntime.Cache items null when under IIS 7 RRS feed

  • Question

  • User1971872355 posted

    Hello

    I have been trying to use application state (both using Application["key"] and HttpRuntime.cache to maintain state across an ASP.Net 4 application; while the methods work perfectly on my dev machine, when I deploy the files on the server the state items disappear; I have seen a similar post here, with a relevant solution suggesting to ensure that the application's application pool is not using many worker threads, but by going to the IIS manager and viewing the pools advanced settings i see that the max number of working processes is set to 1.

    Any ideas of what can possibly be going on? I need this quite urgently, so I would appreciate a quick reply;

     

    thanks

     

    chris

    I am explaining a bit more below:

    I have been developing an ASP.Net 4.0 web application, and I have used the HttpApplicationState class with its Contents property to set some variables in the Application_Start event of the Global_asax file.

    While the application runs as expected on my development machine, when it is deployed on the production server running IIS7 the values returned for the application state variables are null. I have tried various code techniques, like using the HttpContext,Runtime.Cache, the Application["key"], and the Application.Contents.Add["key",Value], all with no success. I am wondering now whether there should be a special configuration on IIS7 on this; researching the topic I see that people say that the application pool in which the application is executed must be served by only a single worker process; I am no IIS7 expert, but selecting the application pool, and viewing its advanced properties, I can see that the pool is configured to have a maximum of 1 worker process, so I believe this should cover it. I have spent a good 2 days on this, so if anyone has any knowledge of this issue, please help!

    thanks

    chris

    Sunday, November 27, 2011 10:15 AM

Answers

  • User-578657687 posted

    Hi,

    the application pool mode used in running the application under IIS. I switched the mode from Integrated to Classic, and the state worked.

    It indicates your issue is related to IIS, I suggest you to post a new thread to IIS fourm:

    http://forums.iis.net/

    You will receive more professional and exact idea for your problem.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 2, 2011 4:05 AM

All replies

  • User1971872355 posted

    Just as an update; looking around on the Net it appears that application pools running in Integrated mode do not work whereas classic mode do; the only issue was that the classic mode pools did not serve the pages correctly (i.e. the pages appeared with no css information). Since I am on a tight schedule, I abandoned the application state and went for session state instead (my tables stored in each session are small (about 30 rows each with about 8 columns and there are three such tables).

    I still am interested if somebody offers some explanation and possible workaround of this problem, as it is indeed wasteful to store the same static data in each user session object; it would be very helpful if the application state actually works for asp.net 4.0 apps running in application pools in integrated mode. 

    Sunday, November 27, 2011 11:33 PM
  • User-578657687 posted

    Hi,

    I guess your Application state losts, because application state is stored in server memory, it is lost whenever the application is stopped or restarted. For example, if the Web.config file is changed, the application is restarted and all application state is lost

    And this post discussed one problem involved losting Application state:

    http://forums.asp.net/t/1320995.aspx

    Tuesday, November 29, 2011 5:06 AM
  • User1971872355 posted

    thanks for your reply; ths issue is that the state is not lost after a while; the state is not loaded to begin with (i.e. the application does not work from the outset).I was expecting the application cache to be loaded on Application_Start event, however it does not. After researching a bot I found a few references on here suggesting an issue with the application pool mode used in running the application under IIS. I switched the mode from Integrated to Classic, and the state worked. However running the app under classic application pool is not an option as some features, like CSS do not work under classic mode (don't know why this is so).

    Tuesday, November 29, 2011 12:33 PM
  • User-578657687 posted

    Hi,

    the application pool mode used in running the application under IIS. I switched the mode from Integrated to Classic, and the state worked.

    It indicates your issue is related to IIS, I suggest you to post a new thread to IIS fourm:

    http://forums.iis.net/

    You will receive more professional and exact idea for your problem.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 2, 2011 4:05 AM