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:
- The classes in System.Management will help you query WMI from within the .NET framework
- MSDN example: connecting to a remote computer to run a WMI query
- WMI scripts: Date/Time tasks
- The Win32_LocalTime class
- 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
精彩评论