I need to change server time from asp.net pa开发者_JS百科ge. Is it possible?
Possible or not, it's a bad idea. And the only way I can think of allowing this is if the user account the app pool is executing under has some serious access rights to the machine; which is also a very bad idea.
Servers should be sync'd with a time server. This is normally controlled at the OS level.
All sorts of funky things can happen once one server in a mix gets out of an acceptable date range.
Which leads us to the question: Why?
UPDATE
You could pinvoke SetSystemTime. This will require the user the app pool is running under to have the SeSystemTimePrivilege. More information and an example of pinvoking here: http://bytes.com/topic/c-sharp/answers/274594-how-set-system-date-c
Again, this is a Bad Idea(tm).
I know this is not what you asked and does not change the server time, only changes the time from the perspective of the asp.net page. If the time difference is a constant then this code might be your friend!
This example adds 1 hour from now...
var today = DateTime.Now;
var duration = new TimeSpan(1, 0, 0);
var answer = today.Add(duration);
Here's a thread explaining how to change systemtime
I can't get SetSystemTime to work in Windows Vista using C# with Interop (P/Invoke)
You will need elevation to get this to work.
精彩评论