Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,
am working on asp.net , C#, SqlServer 2005.
I want to redirect it to Underconstruction page if time is not updating.
if database time is less than 5 minutes when compare to system time...it must redirect to underconstruction page. else it should be Home.aspx.
This is my code.
C#
protected void Page_Load(object sender, EventArgs e)
    {
       // lblUpdate.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-60).ToLongTimeString();

       SqlConnection con = new SqlConnection("Data Source=IT-PC;Initial Catalog=collegeDB;User ID=sa; Password=12345;");
       

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "Select timeupdate from timeLastUpdate";

        using (con)
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                lblUpdate.Text = reader["timeupdate "].ToString();

                lblUpdate.ForeColor = Color.Red;
            }
        }
}

If time updating stops it must redirect to underconstructionpage.aspx
else
redirect to Home.aspx
Please help me, Thanks.
Posted
Updated 9-Oct-12 21:01pm
v2

hi, it will work:
C#
protected void Page_Load(object sender, EventArgs e)
    {
            // lblUpdate.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-60).ToLongTimeString();

            SqlConnection con = new SqlConnection("Data Source=IT-PC;Initial Catalog=collegeDB;User ID=sa; Password=12345;");

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "Select timeupdate from timeLastUpdate";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    lblUpdate.Text = reader["timeupdate "].ToString();

                    lblUpdate.ForeColor = Color.Red;

                    if (Convert.ToDateTime(reader["timeupdate "].ToString()) < DateTime.Now.AddMinutes(-5))
                    {
                        Response.Redirect("underconstructionpage.aspx");
                    }
                }
            }
    }
 
Share this answer
 
Hi Use the below code
C#
protected void Page_Load(object sender, EventArgs e)
    {
       // lblUpdate.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-60).ToLongTimeString();
       SqlConnection con = new SqlConnection("Data Source=IT-PC;Initial Catalog=collegeDB;User ID=sa; Password=12345;");       
 
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "Select timeupdate from timeLastUpdate";
        DateTime lastupdatetime;
        using (con)
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
 
            if (reader.Read())
            {
                lastupdatetime = Convert.ToDateTime(reader["timeupdate "].ToString());
                lblUpdate.Text = lastupdatetime.ToString();
                lblUpdate.ForeColor = Color.Red;
            }
        }
        if(lastupdatetime.AddMinutes(5) > DateTime.Now)
        {
            Response.Redirect("HomePage.aspx");
        }
        else
        {
            Response.Redirect("underconstruction.aspx");

         }
}

Also you should clean all the resources.
 
Share this answer
 
v3
I think you can write that code at Global.asax file at session start to get time from the database and then compare it.

if you condition satisfy for less then 5 min then you can directly redirect to underconstrunctionpage.aspx else no redirection. and it will display home.aspx as usual.

I hope this would be helpful. Let me know if you need any further help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900