如果时间没有更新,请重定向到另一个页面 [英] redirect to another page if time is not updating

查看:65
本文介绍了如果时间没有更新,请重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
正在使用asp.net,C#和SqlServer2005.
如果时间没有更新,我想将其重定向到Underconstruction页面.
如果与系统时间相比,数据库时间少于5分钟...则它必须重定向到建设中页面.否则应该是Home.aspx.
这是我的代码.

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.

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;
            }
        }
}


如果时间更新停止,则必须重定向到underconstructionpage.aspx
其他
重定向到Home.aspx
谢谢.请帮助我.


If time updating stops it must redirect to underconstructionpage.aspx
else
redirect to Home.aspx
Please help me, Thanks.

推荐答案

我认为您可以在会话开始时在Global.asax文件中编写该代码,以从数据库中获取时间,然后进行比较. br/>
如果满足条件的时间少于5分钟,则可以直接重定向到underconstrunctionpage.aspx,否则无需重定向.它将照常显示home.aspx.

我希望这会有所帮助.让我知道是否需要进一步的帮助.
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.


请使用下面的代码
Hi Use the below code
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.


它将起作用:
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");
                    }
                }
            }
    }


这篇关于如果时间没有更新,请重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆