Web.config appsetting issue
-
Hey guys, I got a strange issue with appsettings in my webconfig. What im trying to do is to set open date and a close date for my application using the following code: Web.config
Custom class
Public Shared VisitorApplicationOpenDate As DateTime = CDate(ConfigurationManager.AppSettings("VisitorApplicationOpenDate"))
Public Shared VisitorApplicationCloseDate As DateTime = CDate(ConfigurationManager.AppSettings("VisitorApplicationCloseDate"))
Public Shared VisitorApplicationsIsOpen As Boolean = (Now >= VisitorApplicationOpenDate) And (Now <= VisitorApplicationCloseDate)
I uses the VisitorApplicationsIsOpen in the application form to check if the application is open. But the problem is, it works but not always. For example the application should of opened this morning but it dit not, when I opened the web.config and saved the file without doing any changes, the application was opened. And it is not the first time it has happened. Any Idea what the problem can be?
-
Hey guys, I got a strange issue with appsettings in my webconfig. What im trying to do is to set open date and a close date for my application using the following code: Web.config
Custom class
Public Shared VisitorApplicationOpenDate As DateTime = CDate(ConfigurationManager.AppSettings("VisitorApplicationOpenDate"))
Public Shared VisitorApplicationCloseDate As DateTime = CDate(ConfigurationManager.AppSettings("VisitorApplicationCloseDate"))
Public Shared VisitorApplicationsIsOpen As Boolean = (Now >= VisitorApplicationOpenDate) And (Now <= VisitorApplicationCloseDate)
I uses the VisitorApplicationsIsOpen in the application form to check if the application is open. But the problem is, it works but not always. For example the application should of opened this morning but it dit not, when I opened the web.config and saved the file without doing any changes, the application was opened. And it is not the first time it has happened. Any Idea what the problem can be?
A shared/static field initializer will only run once, usually when the class is first accessed. If that happens when the current time is not within the range, then the field will be initialized to
False
. Try changing theVisitorApplicationsIsOpen
field to a property:Public Shared Readonly Property VisitorApplicationsIsOpen As Boolean
Get
Return (Now >= VisitorApplicationOpenDate) And (Now <= VisitorApplicationCloseDate)
End Get
End Property
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer