Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Web.config appsetting issue

Web.config appsetting issue

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blikkies
    wrote on last edited by
    #1

    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?

    Richard DeemingR 1 Reply Last reply
    0
    • B Blikkies

      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?

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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 the VisitorApplicationsIsOpen 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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups