我在做网站页面的时候,需要做到获取访问该网站的总人数和当前在线的人数,同时也要获得到当前系统的时间(要是动态的,而且要是英文版的)。可是我在做完这些的时候动态时间获取的小时值和系统的时间相差好几个小时,同时在获取当前网站的访问总人数和在线人数在不同的浏览器中运行后得到的数值都不一样,这个是怎么回事!求大神指教!附录代码(我是用母版页加用户控件做的):
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Time.ascx.cs" Inherits="uc_Time" %>
<div>
    <%--<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>--%>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" ForeColor="Black" Style="text-align: left;
                width: 382px; padding-top: 22px" Text="Label" Width="200px"></asp:Label><br />
            <asp:Label ID="Label2" runat="server" ForeColor="Black" Style="text-align: left;
                padding-top: 10px" Text="Label" Width="200px"></asp:Label>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Timer ID="timer" runat="server" OnTick="timer_Tick" Interval="1000">
    </asp:Timer>
</div>public partial class uc_Time : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e) 
    {    }    protected void timer_Tick(object sender, EventArgs e)
    {
        int allUser = (int)Application["AllUser"];
        int onUser = (int)Application["OnUser"];
        Label1.Text = "Time:" + System.DateTime.Now.ToString("r");
        Label2.Text = "Total:" + allUser + "&nbsp;&nbsp;&nbsp;" + "Online:" + onUser + "<br/>";
       // Response.Write(Application["Chat"] as string);
    }
}

解决方案 »

  1.   

    1、服务器时间,有时候不同的语言产有不同的区域时间,如果是多语言,最好服务器是世界时(格林尼治时),客户端根据不同的区域则对世界时进行相应的加减就可以了,如北京时间与世界时相差8小时;
    2、至于在线人数,需要根据需求,如是否需要登陆,如果登陆以后才算的话,需要做登陆会话管理,若不需要登陆对于ASP.NET 来说,只要不同客户端或浏览器访问在服务器都会产生一个会话(启用会话的前提);
    3、页面访问数也是需要根据需要的,如页面访问一次算一次,还是同一会话访问只算一次;
    4、把这些都确定了,就好搞了