限制数量的用户访问asp.net网站 [英] Limiting number of users accessing asp.net website

查看:119
本文介绍了限制数量的用户访问asp.net网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是限制(并发)用户访问一个Web应用程序,任何一个可以引入销售网站/应用程序客户端,如何增加用户数远程访问它的数量的最佳方式?

What is the best way to limit the number of (concurrent) users accessing a web application that any one can introduce for selling website/application to client and how to increase the number of users accessing it remotely?

推荐答案

如果您使用过程中的会话状态管理,您可以使用HttpApplicationState类,通过引入Global.asax文件,并把这样的事情在code背后:

If you use the in-process session state management, you can use the HttpApplicationState class, by introducing the Global.asax file and putting something like this in the code behind:

void Application_Start(object sender, EventArgs e)
{
    Application["ActiveSessions"] = 0;
}

void Session_Start(object sender, EventArgs e)
{
    try
    {
    	Application.Lock();

    	int activeSessions = (int) Application["ActiveSessions"] + 1;
    	int allowedSessions = 10; // retrieve the threshold here instead

    	Application["ActiveSessions"] = activeSessions;

    	if (activeSessions > allowedSessions)
    		System.Web.HttpContext.Current.Response.Redirect("~/UserLimitReached.aspx", false);
    }
    finally
    {
    	Application.UnLock();
    }
}

void Session_End(object sender, EventArgs e)
{
    Application.Lock();
    Application["ActiveSessions"] = (int)Application["ActiveSessions"] - 1;
    Application.UnLock();
}

然后,在你UserLimitReached.aspx会叫HttpSession.Abandon()来有效地终止当前会话,因此不计入限额。你必须自己找出休息。 :)

Then, in the UserLimitReached.aspx you would call HttpSession.Abandon() to effectively terminate the current session so it does not count towards the limit. You'll have to figure out the rest yourself. :)

这篇关于限制数量的用户访问asp.net网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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