views:

242

answers:

3

Hi,

I have an application I have just deployed which, for complicated reasons, stores all the data from the database in a module the first time any data from the specific table is required (i.e. when a customer requests to view a product for the first time, all the product data is stored in the ProductManager class (of which an instance is stored in a shared property of the SiteContent class, making the ProductManager easily accessible from any page).

Now forget that you are probably now glaring at me for using this approach.. I am sure it has its inefficiencies but I have only been studying .Net for a year or so now so I am still learning.

One thing I have noticed is that I can go on the site once, then revisit it 5 minutes later and it will load all the data into the ProductManager class again. It seems this is a .Net application timeout thing - since the session timeout is set to 30 minutes and, when I am logged in on the administration frontend, it logs me out after 5 minutes (ish).

Does anyone have any idea how to change this? Is there any way I can change this in the code without having to contact the hosting company? If not in the code is there any way to change this in the web.config?

Thanks in advance.

Regards,

Richard

More details:

The module (SiteContent) stores an instance of each "Manager" class - pages can call Manager.Create, Manager.Update, Manager.Remove etc etc and use Manager.Items to access a list of items stored in the manager (for example SiteContent.ProductManager.Items returns all the products stored in the database and SiteContent.UserManager.Items returns a list of all users stored in the database). It seems that, because it is a module, it is shared between users and page loads.

I have tried coming back to a page and reloading it after 3 - 4 minutes and it loads fine, but after about 5 minutes it takes a few seconds to load the page again (not long - but I would rather it didnt add a few seconds to the first page load every 5 minutes).

This is particularly annoying for my Dad (the owner of the business) when he is entering products which take more than 5 minutes to enter or which, when entering them, he takes a break for 2 minutes and then it asks him to login again on clicking submit, losing all his data at the same time. I am not using a method specified in the authentication section of the web.config for logging in - I am using a form with a login button, and clicking it compares the entered username and password to that of each user (through SiteContent.UserManager.Items).

Other than this I dont know exactly what you want to know.. can you expand on any specifics you need to know?

On doing some googling I have found out that there is an executionTimeout and a shutdownTimeout which I will have a go at changing..

More details:

hmm seems I just solved the page load time problem.. I noticed that the test database was over 13MB and the live database was only 3MB. I had a little investigate into this.

Basically the error logger will log every time and image cant be found if it is requested in the catalogue page. The test site hasnt been kept up to date with the images, since it doesnt need to be, so the missing image table had gone up to > 10MB.. gonna have to disable image logging on test. I deleted everything from that table and everything loads quickly now.

As for the timeout thing, I am going to leave that till a later date now - I am spending way too much time on this when I have more important things to prioritize at this moment - this website was actually my final year project at uni, and I have a presentation about it on Friday.. will be sure to add more details to this post about how I get on with this problem in the future, so please check back here from time to time..

Thanks for spending so much time on this..

Regards,

Richard

+1  A: 

ASP.NET have various different timeouts, if you use FormsAuthentication then FormsAuthentication has its own timeout which is different from Session Timeout, you can check System.Web's configuration section of forms authentication, you will know where to increase your timeout.

Plus you will have to write IHttpModule because, after Authentication is performed, you can improve your design by initializing proper session values in the event handlers offered by http modules.

Akash Kava
I am not using any of the asp.net built in authentication mechanisms - the authentication method is set to None. The sessionState timeout is set to 60 (which I believe is in minutes).
ClarkeyBoy
A: 

I don't think either of those timeouts is relevant.

If I read you right, the first page load triggers the data load. The page gets a reference to the data, stores it at the global scope, and uses it from there.

If this is correct, it sounds like the Page data is being released after a few minutes (which is reasonable). Since this releases the last reference to the Module, the Module gets garbage-collected.

Have you tried storing a reference to the data in the Session object? That persists a lot longer.

It sounds like you're trying to do data cacheing, maybe that's what you should be googling.

Edit Since what you are doing (data entry) is very straightforward, one of your basic assumptions is probably wrong, so let's look at a couple of your comments.

  1. If your webserver is in some remote location, then your local connection speed is probably irrelevant to how fast the database is read, but if you really mean "a few seconds", that could easily be why the page takes time to load.

  2. How much data are you trying to keep around? Kilobytes? Megabytes? Gigabytes? If it's kilobytes, can you keep it on the page?

  3. Putting anything in Application_End() makes no sense. That only gets called when the application itself has sat unused for so long (say, 20 minutes) that IIS tells it to end. Nothing you do then will make any difference.

  4. The Managers don't expire, the Page expires, and you probably shouldn't change that.

  5. When you tried caching, did you still have the "database data gone, user logged out, data entry lost" problem? Or did it just become "performance slow"?

egrunin
On some further research I agree with you about both of those timeouts being irrlevant.I think storing it in sessions would be even more inefficient wouldnt it? I tried storing it in the application object but that, apparently, takes up a lot of resources. I am wondering if I could put something in the Application_End of the global.asax.vb file which reinitialises all of the manager classes when the application ends.Do modules have a timeout? If so it could be that the module is timing out, causing all the manager instances to (maybe) still exist without anything referencing them.
ClarkeyBoy
Just looked into data cacheing. I have changed it to store each manager instance in the cache.. I have made a lot of changes to the development site which I will need to make to the test site - this could take a few hours but I will get it tested with data cacheing implemented this afternoon sometime, all things going well.Thanks for the help.Regards,Richard
ClarkeyBoy
hmm it just occurred to me - if this is simply the managers expiring then why is it logging us out after 5 minutes when the session timeout is set to 60 minutes? I mean every page load it loops through the user instances and compares them to the session username and password, it doesnt reference a session value to the user instance.. in theory, if there is no other timeout taking effect after 5 minutes, it should still be logged in.Richard
ClarkeyBoy
Well caching has made it a bit faster, but not much difference really. I am starting to wonder if it is our internet connection which is causing the issue - we have broadband but are at the end of the line, so we only get dial up speed. My original thought was that it wouldnt have any effect in this case since the page loading bar does not start going up for a few seconds - that says to me that the browser has not started loading the page. I dunno.. I am completely at a loss as to how to solve this.. its doing my head in..
ClarkeyBoy
Added more details for you..
ClarkeyBoy
A: 

You mix 2 timeouts:

  1. Session timeout - how often server cleans memory from session map
  2. Auth-cookie timeout - how often client browser cleans cookies.

Information about 5 mins is stored on client side in cookies, to change this time look at following line in web.config:

    <authentication mode="Forms">
        <forms name=".ASPXFORMAUTH" 
              protection="All" 
              loginUrl="Login.aspx" 
              timeout="20"                 
              defaultUrl="Default.aspx"/>
    </authentication>
Dewfy