Forum Moderators: open
I am having a problem with an ASP.NET application i am working on. I new to ASP.NET so I'm not sure if I'm doing this right.
I am working on a website that has an oil price listed throught several pages. In the global.asax file i have the following code.
Sub Application_Start(ByVal sender As Object, ByVal e
As EventArgs)
' Fires when the application is started
Application("OilPrice") = "1.14"
Application("PrePay") = "1.14"
End Sub
I reference these variables on other pages. Everything works correctly up to this point. I have another page were the price can be changed. Once a new price is changed it reflects on all pages. The problem is after a few hours or the next day. The price always resets to the "1.14" in the global.asax file. It was my understanding that the Application_Start event only occurs once, the first time the application is accessed.
Is my assumption correct? If so what could be causing the variables to be reset? Thanks!
IIS6 has a new default behaviour where the
httphandler is restarted periodically.
If that is happening, then it would not be
surprising that the global.asax is being
fired again.
If this is happening then you need to have
an online source for this info that global.asax
can grab the correct number from without waiting
for a manual update.
If that's correct, you should be able to use the Application_OnEnd event to save the current values of those variables to a database or XML file before the Application shuts down. Then in Application_OnStart, you can read those variables back, rather than use static values. That may even work if, as plumsauce says, the problem is that the httphandler is restarting.
Good luck!
g.
Then you would only hit the DB when your application is restarted for the first time, the values are changed, or your cache entry expires. This way your data will persist over application_restarts, reboots, and other things.
Don't hard code any values unless they are going to be the same for a very long time.
.Net has very simple XML functions built in. Look at the ReadXML & WriteXML methods on the dataset object.
Ross