application限制人数的问题

yzaiml 2008-07-07 11:28:08
void Application_Start(object sender, EventArgs e)
{
int UserAmount = 0;
UserAmount = Convert.ToInt32(Application["UserKey"]) + 1;
if (UserAmount >= 10)
{
//...进入程序
}
else
{
//...跳转错误页面
}
}
void Application_End(object sender, EventArgs e)
{
Application["UserKey"] = Convert.ToInt32(Application["UserKey"]) - 1;
}
限制程序只能有10人 超出人数就弹出错误页面
但是我上面好像无效 是不是哪里有问题
...全文
92 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzaiml 2008-07-07
  • 打赏
  • 举报
回复
thank you
满衣兄 2008-07-07
  • 打赏
  • 举报
回复
Login.aspx

//验证通过.....
if (Convert.ToInt32(Application["UserKey"]) < 10)
{
Application["UserKey"] = Convert.ToInt32(Application["UserKey"]) + 1;
//...进入程序
}
else
{
//...跳转错误页面
}
满衣兄 2008-07-07
  • 打赏
  • 举报
回复
void Application_Start(object sender, EventArgs e)
{
Application["UserKey"] = 0;
}
Login.aspx

//验证通过.....
Application["UserKey"] = Convert.ToInt32(Application["UserKey"]) + 1;
if (Convert.ToInt32(Application["UserKey"]) < 10)
{
//...进入程序
}
else
{
//...跳转错误页面
}
Session_End
if(Convert.ToInt32(Application["UserKey"]) > 0)
{
Application["UserKey"] = Convert.ToInt32(Application["UserKey"]) - 1;
}


====
Application_Start在你的程序第一次启动时加载一次,保存在服务器内存.
yzaiml 2008-07-07
  • 打赏
  • 举报
回复
好像还是不行啊?这里哪里的问题啊

超过还是登录上去了
满衣兄 2008-07-07
  • 打赏
  • 举报
回复
void Application_Start(object sender, EventArgs e)
{
Application["UserKey"] = Convert.ToInt32(Application["UserKey"]) + 1;

int UserAmount = 0;
UserAmount = Convert.ToInt32(Application["UserKey"]) + 1;
if (UserAmount >= 10)
{
//...进入程序
}
else
{
//...跳转错误页面
}
}
yzaiml 2008-07-07
  • 打赏
  • 举报
回复
你是说这个代码应该写在
Session_Start
Session_End
这里?
jcrjia 2008-07-07
  • 打赏
  • 举报
回复
Application_Start
是第一个访问网站的用户触发的

可以在Session_Start里实现
Session_Start 是每个用户访问你网站第一个页面时触发
sssjjjpppsjp 2008-07-07
  • 打赏
  • 举报
回复
不会就帮你顶
yzaiml 2008-07-07
  • 打赏
  • 举报
回复
哪里出错了?
yzaiml 2008-07-07
  • 打赏
  • 举报
回复
void Application_Start(object sender, EventArgs e)
{
int UserAmount = 0;
UserAmount = Convert.ToInt32(Application["UserKey"]) + 1;
if (UserAmount >= 10)
{
//...在应用程序启动时运行的代码
}
else
{
//...跳转错误页面
}
}

62,017

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧