asp.net 단일 사용자 로그인 클래식 솔루션
, WEB , !
, , 。
, 1, 0, , 1 , , , , , , IE, , , , : , , , , 。
, .net 。 :
: global.asax , Session_End :
Hashtable h = (Hashtable)Application["online"];
if (h[Session.SessionID] != null)
h.Remove(Session.SessionID);
Application["online"] = h;
: web.config , system.web
<sessionState mode="InProc"></sessionState>
global.asax session_end 。
: , , , 。 , 。
private void isLogin()
{
Hashtable h = (Hashtable)Application["online"];
if (h == null)
{
h = new Hashtable();
}
// Application ( )
IDictionaryEnumerator e1 = h.GetEnumerator();
bool flag = false;
while (e1.MoveNext())
{
if (checkCookie(e1.Value.ToString()))
{
flag = true;
break;
}
}
if (flag)
{
Response.Write("<script defer language='javascript'>alert('This user is online!');history.go(-1);</script>");
}
else
{
loginLogic login = new loginLogic(this.txt_user_id.Text.Trim(), this.txt_password.Text.Trim());
if (!login.getLoginStatus)
{
Response.Write("<script defer language='javascript'>alert('Invalid UserID or password.Please try again.');</script>");
}
else
{
//
DateTime now = DateTime.Now;
string cookieValue = now.Year.ToString() + now.Month.ToString() + now.Day.ToString() + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString() + now.Millisecond.ToString();
// userid +
h[Session.SessionID] = this.txt_user_id.Text.Trim() + "-" + cookieValue;
Application["Online"] = h;
// cookie
Response.Cookies["hqs"].Value =cookieValue;
Response.Cookies["hqs"].Expires = DateTime.Now.AddDays(1);
// session
Session["userid"] = this.txt_user_id.Text.Trim();
Response.Redirect("Manage/index.aspx");
}
}
}
private bool checkCookie(string appValue)
{
bool isExist = false;
if (Request.Cookies["hqs"] != null)
{
string cookieValue = Request.Cookies["hqs"].Value;
char[] sp = new char[1]{'-'};
string appUserid = appValue.Split(sp)[0].ToString();
string appCookie = appValue.Split(sp)[1].ToString();
if (appUserid == this.txt_user_id.Text.Trim() && appCookie != cookieValue)
isExist = true;
}
return isExist;
}
: VS2005 WEB , IIS .
: session timeout 20 , , , , session , global.asax session_end , ,20 , , 。 IE , , 。
,session timeout ,20 。 :
<sessionState mode="InProc" timeout=" "></sessionState>
------------------------
, , ,session 20 END , , 。 。 , 。
: ,
、 , , 。 ASP.NET , 。
Cache , Cache , Session , , Session , Cache ; Cache , , 。
string sKey = username.Text.ToString().Trim(); // Cache Key
string sUser = Convert.ToString(Cache[sKey]); //
if (sUser == null || sUser == String.Empty)
{
TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);// Session
HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null);// cache
//
}
else if (Cache[sKey].ToString() == sKey)//
{
ClientScript.RegisterStartupScript(GetType(), " ", "<script>alert(' , ');</script>");
return;
}
else
{
Session.Abandon();//
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.