none
Overriding system functions RRS feed

  • Question

  • We need to test a asp.net website with future date which also uses windows authentication(we use domain credential). So i need to change the date in the development windows 2003 server which is added into our corporate domain controller. Currently what is happening is whenever i change the time in windows 2003 development server, it automatically changes to domain controller time. So i had stopped the Windows Time service. Now i am unable to use domain credentials as AD denies due to time difference.

    Is there a way i can use different date and still test my website with domain credentials?

    Is it possible to override asp.net application to get different system time?. May be i should be able o override system implementations. Like System.DateTime.Now to return my custom date.

    Not sure if i am overlooking this problem.


    Mr Genius
    Friday, July 29, 2011 9:54 PM

All replies

  • A simple hack against the ASP.net engine just won't cut it because Acitve Directory will not authenticate a user to a PC that is more than 20 minutes off of the DC's time.  This is just how kerberos v5 works.  Sorry.  What you need: A QA Domain.  This way you advance the clock of the QA domain controller(s) and voilá!, you are good for testing. 
    MCP
    Saturday, July 30, 2011 7:01 PM
  • I think asp.net HttpHandler is invoked after the user is authenticated. So DC should not have any problem. I just need my application to get the future date. Just wondering if i can override/hide System.DateTime.Now with my implementation.

    Mr Genius
    Sunday, July 31, 2011 3:44 AM
  • Hi,

     

    Thank you for your question, we're doing research on this case, it might take some time before we get back to you.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 1, 2011 6:41 AM
  • If all you need to do is change the date in code you could create a method GetCurrentTime() and return System.DateTime.Now.Add().  This isn't standard so you'd need to remember to change it everywhere in your code and use ir moving forward.  So a business rule of "any time you need the current time use this method." would need to be established.  I don't love that, but it gets you around AD and able to test.
    Monday, August 1, 2011 5:44 PM
  • Thanks for the reply. This is not an option for now as we have the huge code base and we do not want to alter the code much for this testing. Looking for a simpler and clean solution.
    Mr Genius
    Monday, August 1, 2011 6:39 PM
  • FYI, you might hit the jackpot if you post @ http://forums.asp.net.  In here, we are probably going to look for more generic approaches that lie within the realm of the framework itself.

     

    And I like Patrick's suggestion.  Huge codebase?  No problem:  Use Find/Replace to alter it, then make the function's body something like this:

    System.DateTime GetCurrentTime()
    {
    #ifdef DEBUG
      return System.DateTime.Now.Add(<whatever you need>);
    #else
      return System.DateTime.Now;
    #endif
    }
    

    And just remember to use GetCurrentTime() from now on, and remember to NEVER EVER deploy the debug build.


    MCP
    Monday, August 1, 2011 8:11 PM
  • Since the application is asp.net, you could try setting the IIS application to use Basic instead of Windows Integrated. (You have to deselect Windows Integrated. Do not have both checked at the same time.)  That way there is no dependency on time, but you can still pass credentials to a backend.  If you are concerned in your test environment with passing username and password in cleartext, then you can add a certificate to your site and use HTTPS.

     

    Tuesday, August 2, 2011 5:12 PM