OdeToCode IC Logo

What's Wrong With This Code? (#11)

Wednesday, February 7, 2007
Joe Developer is tasked with displaying the start date of his ASP.NET application. Joe thinks he'll just add a DateTime field to global.asax and initialize the field during the Application_Start event.

<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        StartDateTime =
DateTime.Now;
    }
    
    
public DateTime StartDateTime;
          
</script>

Whenever Joe needs to display the application start date, he accesses this public field.

Joe doesn't know what is wrong, but he is sure of one thing – the date that is displaying on his pages is not the date when the application started. Can you help out Joe one more time?