简体   繁体   中英

Validate and reset system clock on ASP.NET website startup?

I have an ASP.NET application that is hosted on a farm of virtual servers with time problems. The symptoms are that when servers startup or reboot they often come up with a bad system time (potentially hours off).

(Obviously the best answer would be to solve the system problem, but that is currently beyond my control...)

So here's the question: Is there are straight forward way for me to get my ASP.NET application to query an authoritative NTP server on startup and then reset the system clock if needed?

Technical assumptions: * ASP.NET 4.0 * Windows 2008 * Full local admin rights on server

You may be able to do this using WMI (Windows Management Instrumentation) . Though I don't have personal experience with doing so, there are numerous examples out there. To start:

  1. The classes in System.Management will help you query WMI from within the .NET framework
  2. MSDN example: connecting to a remote computer to run a WMI query
  3. WMI scripts: Date/Time tasks
  4. The Win32_LocalTime class
  5. Using the WMI Update Query Language to update system information

Hope that sets you off in the right direction.

I don't think the application is the right place to be resetting system time. If I'm not mistaken, Windows Time Service can manage this:

http://www.windowsnetworking.com/articles_tutorials/configuring-windows-time-service.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM