代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int Counter;
Application.Lock();
//锁定,不允许其他用户修改变量
Application.Set( "Counter ", Application.Count + 1);
//访问计数增加
Application.UnLock();
//开锁,允许其他用户修改变量
MyCounter.Text = "您是第 " + Application.Count + " 位访客 ";
}
}
------解决方案--------------------------------------------------------
代码写在Global.asax.cs里面:
protected void Application_Start(Object sender, EventArgs e)
{
Application[ "Counter "] = 0;
}
protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock();
Application[ "Counter "] = Convert.ToInt32(Application[ "Counter "]) + 1;
Application.UnLock();
}
给的分太少了,所以以上代码我没测试...