0

How to get Date Time from Internet and compare with one specific date, if the date is equal and greater then allow to register page else redirect application closed the page. My below code have one issue is that if a user will change system date, then its going to redirect to register page. That's why I need internet and redirect based on condition. And one more thing I am executing my application in local host.

Below is my C# code:

string date = "01/04/2016";
DateTime myDate = DateTime.ParseExact(date, "dd/MM/yyyy",
                           System.Globalization.CultureInfo.InvariantCulture);
if (DateTime.Today>=myDate)
{   
    // Allow redirect to registration page.
}
else
{      
    Response.Redirect("ApplicationClosed.aspx");
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Mr doubt
  • 51
  • 1
  • 10
  • 42
  • 1
    Nothing here is using the *Client* date time. Its using *Server* date time. You can change it, as its probably running on your machine (The *server*), but users of your website will not be able to affect the date returned by `DateTime.Today` – Jamiec Feb 29 '16 at 10:34
  • 3
    That looks like ASP.Net code. The only risk is that if the user changes the date *on the server*. But if that's your risk model, you can't save yourself. You can't trust (your) code running on someone else's machine. – Damien_The_Unbeliever Feb 29 '16 at 10:35
  • This post refer to Internet time http://stackoverflow.com/questions/6435099/how-to-get-datetime-from-the-internet – Irshad Feb 29 '16 at 10:53
  • I got answer, because I am in local server that why taking time from my system, if I will host into live then it will take from live server time. @Jamiec – Mr doubt Feb 29 '16 at 11:15
  • Yes the code is asp.net code, as I add registration start date like 01/04/2016, can I add closing date for my registration and my closing date is 20/05/2016.@Damien_The_Unbeliever – Mr doubt Feb 29 '16 at 11:20

0 Answers0